![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2006
Posts: 9
Rep Power: 0
![]() |
array of listed lists
Hey everyone, im doing an project for uni, and i have to make a dictionary, which is an array of linked list, where each element of the array is a linked list which stores all the words starting with a certain letter of the alphabet.
the words for the dictionary are ment to be read in from a dictionary and then sorted in the array of linked lists. im still new at programming and cant understand how to make an array with each element consisting of a linked list. any help would be great! thx! |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
I believe you would create an array of lists just like you would create an Array of anything else.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Expert Programmer
|
I'm not sure what your problem is. However, I would recommend using an ArrayList to store the LinkedList objects because it is much more flexible (you can add and remove elements easily). If you choose to go about your task in this way, you might use code similar to the following:
ArrayList<LinkedList> dict = new ArrayList<LinkedList>(); dict.add(linkedListObject1); dict.add(linkedListObject2); // ... LinkedList[] dict = new LinkedList[NUM_ELEMENTS]; dict[0] = linkedListObject1; dict[1] = linkedListObject2; // ... |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Dec 2005
Posts: 57
Rep Power: 0
![]() |
Creating an array of objects is no different than creating an array of primary data types. Im assuming you know how to make an array of primary data types, but just to refresh your memory:
int[] a = new int[7]; //create the array a[0] = 0; // intialize indexes a[1] = 1; ... As you probably already know, this creates an array of 7 integers. Creating an array of LinkedList objects is no different. LinkedList[] dictionary = new LinkedList[26] //create the array Now, you must remember all that does is create the pointers in memory. None of these indexes are initialzed. In order to actually use the linked lists, you will have to initialize each one. a for loop does the trick: for(int i = 0; i < dictionary.length; i++)
{
dictionary[i] = new LinkedList();
}Your dictionary is now ready to go! Now we just use it as we would any linked list: dictionary[0].add("apple");
dictionary[0].add("amazing");
dictionary[1].add("ball");
... |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Assigning an array of lists | deanosrs | C | 42 | Apr 13th, 2006 1:35 PM |
| changing size of an array | Eric the Red | Java | 3 | Apr 3rd, 2006 8:19 PM |
| Changing Array structures to Linked Lists? | kalulu | C | 4 | Nov 29th, 2005 6:33 AM |
| Installing IPB 2.03 | bh4575 | Other Web Development Languages | 0 | Apr 23rd, 2005 2:36 AM |
| Converting 1-dimensional array to 2-dimensional array | Tazz_Mission_13 | Java | 6 | Apr 8th, 2005 11:58 AM |