![]() |
|
#1
|
|||
|
|||
search linked listHI,
I am trying to build a program that searches a linked list for a number that the user puts in. If the number is there I want to show its position in the list. If it is not there I want to show zero. I have a lot of the program written, the only problem is, is that it is sort of backwards. I am new at this. I have a delete function, and I thought a search function would do about the same thing except instead of deleting the number the user puts in, I want to show its position. But I am deleteing it still. In my code where I have "delete" I don't know what to put here. Can someone set me straight? Thanks so much.....here is my code .cpp & .h CPP / C++ / C Code:
CPP / C++ / C Code:
Last edited by LuciWiz : 16-Apr-2005 at 09:52.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|||
|
#2
|
||||
|
||||
|
Well, I see you cycle through the list until you find the desired value. I suggest you use a variable for counting which position in the list you are at. You would increment this variable until you find the required value. Then, just display it, or use a return to give it to the calling function.
Kind regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#3
|
|||
|
|||
How to post code correctly on this forum?Sorry about the last post "code", for the life of me I can't find HOW to post correctly. Can someone help me out?
Thanks |
|
#4
|
||||
|
||||
|
Hello,
You can post code by enclosing your code in [C] / [C++] tags. For a following example, copy the bolded line and paste it in a post. You will see that it encloses any text as a code block: [C]int main() { return 0; }[/C] Hope this helps. - Stack Overflow __________________
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [C] / [C++] tags. Your question may have been asked before, try the search facility. |
|
#5
|
||||
|
||||
|
Just follow the link in my signature. Or you could hit the "reply" button bellow (Not the big "post reply" button, the little one in the right) and see how I included this piece of code:
CPP / C++ / C Code:
[Edit] Wow, Stack, it seems you beat me to the "Submit Reply" button by a few seconds! Congratulations [/Edit] __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#6
|
|||
|
|||
|
I think someone slipped me a stupid pill. Thank you for your replies. I read about the [c++] but was looking for a button or something... duh
Thanks again. Last edited by itsmecathys : 16-Apr-2005 at 10:16.
Reason: messed up
|
|
#7
|
||||
|
||||
|
Quote:
![]() Quote:
- Stack Overflow __________________
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [C] / [C++] tags. Your question may have been asked before, try the search facility. |
|
#8
|
|||
|
|||
Still having prolemsWhen I run my program, it is suupose to show me the number the user put in. there are a total of 6 numbers, if the user guesses a number that is in the list, it should show that number. BUT, it is showing every other number, except the number the user put in. I hope I explained this good enough.
|
|
#9
|
||||
|
||||
|
Quote:
You probably printed everything in the while, right? I didn't say that. When you exit the loop, if you found the value, then print the counter. Please show us the code you've come up with now. Only the relevant function, please. Best regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#10
|
|||
|
|||
|
OIC.....thanks again
|
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Merge sort on a linked list | Temujin_12 | C++ Forum | 1 | 06-Mar-2008 21:33 |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 08:44 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 14:12 |
| adding to linked list from external file | cghv | C Programming Language | 3 | 09-Mar-2005 14:36 |
| Search Engine Positioning 101 and 201 "How To" Tips... | 000 | Search Engine Optimization Forum | 0 | 29-May-2003 11:34 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The