![]() |
|
#1
|
|||
|
|||
Question about linked list and queueI'm doing an assignment about linked list and queue. I have got a trouble in queue. I have added all the items from a txt file to queue. However, after displaying the context of the queue, it become empty.
1) how to solve this problem ? 2) In the linked list, it contains the restaurant name that is same as the queue. Is it possible to display other information after comparing the linked list with queue ? CPP / C++ / C Code:
Last edited by JdS : 02-Sep-2004 at 09:19.
Reason: Please insert your example C/C++ codes between [c] and [/c] tags
|
|
#2
|
||||
|
||||
|
Quote:
From your piece of code, I'm guessing you "damage" your first element. Well, actually, what I mean is that you change it's value, and then, when you try to start at the "front", you actually start at the end. Quote:
Instead, why not just use tmp to iterate throw the queue's elements? CPP / C++ / C Code:
Regards, Luci __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#3
|
||||
|
||||
|
I missed one
![]() Quote:
What do you mean? Do you have a queue for each node in the linked list? Or do the two structures mirror each other? Well, if this is the case (number 2 However, I'm not sure if this was your question....please explain. Regards, Luci __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#4
|
|||
|
|||
linked list and queueActually, it has a linked list and each node of this list contains different restaurant name and number. And It has a queue that contains restaurant name, cuisine no and operation mode. Hence, it has a meny displaying the restaurant number and name on the screen. When user enter the number, the restaurant name in the linked list search the queue in order to show the cuisine no and operation mode. I get confused because of searching in the queue by using linked list item. Also I'm a beginner for writing program. That's why ....
|
|
#5
|
||||
|
||||
|
Quote:
Well, then just do as I said. Something like this: CPP / C++ / C Code:
Hope I got it right... Regards, Luci __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#6
|
|||
|
|||
|
After following your guide, the queue works for display its context. And now, I got another problem for comparing with linked list and queue. (char * input) is the restaurant name from linked list and it is used to compare w/ the queue tmp -> item(stored by char *). I can sure that both input and tmp -> item containing the restaurant name. However, the program is stopped by using the if loop and only displaying "true" no matter the data that are right or not. Did I do sth wrong b4 ?
CPP / C++ / C Code:
Last edited by JdS : 02-Sep-2004 at 09:20.
Reason: Please insert your example C/C++ codes between [c] and [/c] tags
|
|
#7
|
|||
|
|||
|
yes, I can do it now. THX
can we be a friend ? |
|
#8
|
||||
|
||||
|
Found was true because strstr returns NULL if the second string is NOT found in the first one. Strcmp however is 0 if the two strings are alike.
So, if input is not found in the first element, Found is TRUE and the while lopp exits. That is why it is always true. It should however work with strcmp. Except you should leave this line of code out, there is no need to go further if you found the node: CPP / C++ / C Code:
Quote:
You can just add me as a friend and I'll do likewise. You are welcome. Regards, Luci __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
Recent GIDBlog
A Week in Kuwait by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| store a list of names in a Queue | dinuka | C++ Forum | 1 | 01-Aug-2004 18:54 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The