Advertisement

linked list help

Started by March 14, 2001 10:31 AM
2 comments, last by Legene 23 years, 10 months ago
Edited by - legene on March 14, 2001 2:03:09 PM
I'm not sure exactly what your code is doing. But look at the following and see if it helps:

struct CircularLinkedList {
    ...
    ...
};

struct DoublyLinkedList {
    ...
    ...
};

struct LinkedList {
    ...
    ...
    CircularLinkedList *CL;
    DoublyLinkedList *DL;
    ...
    ...
};

So your linked list structure can reference either to a circularly linked list and doubly linked list for every node in the linked list. When you traverse the singly linked list these can be accessed by the pointers CL and DL.

------------------------------------------------
DaWizard
http://members.home.com/ahmadkabani
http://www.geocities.com/ahmadkabani
------------------------------------------------


Edited by - DaWizard on March 14, 2001 11:46:20 AM
------------------------------------------------DaWizardhttp://www.geocities.com/ahmadkabani------------------------------------------------
Advertisement
Ok, now I understand the pointer part in the linked list struct and how it points to another struct. The part that i do not understand is how to implement the new pointer to the struct so that say i can create a circular list for a certain album name.
In other words, how do I point to an album name, then to the pointer to another struct, then to a node in the circular list?
I hope that what I am talking about is somewhat understandable. I am really confused, so i apologize if it isn't.

for instance, if i wanted to use the following and pass it the name of an album title, how would i set up the pointers so that i could display the tracks for the album?

void linklist::display_track(char input[])
{
clink* current = first;
while(current != NULL)
{
if(current->cdata!=NULL)
{
cout << current->cdata< current = current->next;
}
else
cout<<"Error"< }

}
//the above is just something i was messing with, it's not right.

Another quick question, would you add trackitem's in the same way that you access the circular list to display the contents. I was just wondering how it would work with two inputs. (one for the album and one for the track).

If this would work, could i modify the one below that i used for my album link list in order to keep track of the tracks?

void linklist::additem(char input[])
{
link* newlink = new link;
strncpy(newlink->data, input, MAX);
newlink->next = first;
first = newlink;
}

thanks again for all the help.

Legene


Edited by - legene on March 14, 2001 12:43:47 PM

Edited by - legene on March 14, 2001 12:44:38 PM
Ok, i figured out the display function, but am still stuck on how to additems using the pointer to the struct.

Legene

Edited by - legene on March 14, 2001 2:27:59 PM

This topic is closed to new replies.

Advertisement