supposed i created a linked list in class A how can class B access it? please give me some examples if any many thanks
A:
One way is to pass the list to both classes through a constructor.
List<X> list = new LinkedList<X>();
A a = new A(list);
B b = new B(list);
parkr
2009-10-02 07:55:31
+2
A:
If the linked list is maintained by class A. You should create an interface that can be used by class B.
I can think of:
- Add, to add to the linked list
- Delete, to delete from the linked list
- Replace, to replace an item
- Lookup, to get an item from the list.
- Length, to get the length of the list.
And there are possibly more (like an iterator) but it should suit your needs.
An other option is to create it outside class A and B and pass it to the classes at construction.
Gamecat
2009-10-02 07:57:33
i am not sure how to create an interface like that.would you mind giving me an example? thanks
ltp00507
2009-10-05 09:19:29
Just add the methods needed to manipulate the linked list to class A so class B can access them.
Gamecat
2009-10-05 10:07:09
A:
Does it have to be a linked list? if you use a different structure that you can control the memory space of, you can use shared memory nicely.
avirtuos
2010-02-18 16:00:14