LINKEDLIST find the "Kth" Element and Delete it!!

Pages: 12
The question here is that I have to ask the user to enter the number to be deleted, or do I have to make the code to do it by itself?

Well, I assume that you would ask the user for the value of K. Since you're being marked on this, I would ask for clarification (although it could be a little late for that now). Another way to do it is to generate a random number for K. If your list has 12 elements, regardless of how you generated K (via the user or some other way), your code should still be able to respond correctly if K < 1 or if K > 12 (in both cases, no nodes should be deleted). If I were a teacher marking this assignment I would focus on the correctness of the routine itself.

On the examples you showed above, your pointing to a specific node(node2, node3, node4, etc). Is there a way to point randomly?

I don't understand what you mean here. Each node always points to the next node. If the list is unordered (i.e. all the numbers have been generated randomly and are in unsorted order), then the first node (with whatever number it holds) still points to the second node (with whatever number that one holds), and the second node still points to the third, and so on.
I spoke about this issue with my proffesor and she said that the purpose of this is to make a "loop"to look for the number. Basically, it's to create a new function(simple one) to search for the number input by the user.

Say:

If you have a list with the following numbers:


List: 32 53 675 23 7 96 2 890 2


with , of course, random numbers, each number has a slot numbered 1st 2nd 3rd 4th ,, etc and the objective is to ask the user which number he/she wasn't to see, and then delete it.

Say, the user wants to she the 3rd number from the list shown above, then the user will request to see "675".

That's all she wanted us to do on this code. She said to complete it by the end of next week, but now,I'm stuck on how to make a loop with pointers in a link list. That is, the loop, can pull the number I want to see(with me being the user for testing purposes) out of the list with random numbers.


something like this is what she wants.

enter a list of numbers,press enter to continue to the next input, and enter -999 to finish the list:
43
54
665
86
324
85
34
862
-999

list:43 54 665 86 324 85 34 862
What occurrence(s) would you like to delete:665

The list has been updated.

Updated list: 43 54 86 324 85 34 862

The list after deleting the smallest element:

list: 42 54 86 324 85 862

Which occurrence would you like see:
(Enter the location you would like to see not the actual number on the list(e.g. 1 ,2 ,3 , 4, 5 etc)
3

Number your requested is: 86

Number located on the 3 slot in the list.

press any key or enter to continue..........

Topic archived. No new replies allowed.
Pages: 12