| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I need to find a way to write a function that would allow me to move the last item in the linked list to be the first one.
Here is how it should look: //Linked list data before "the move" 15 25 35 50 //calling function x.shiftRight() x.shiftRight(); //Display new arrangement within the Linked List. x.displayList(); //New output 50 15 25 35 //another x.shiftRight() x.shiftRight(); //another displayList() displayList(); //New output 35 50 15 25 Please help me to write the shiftRight() function. |
|
#2
|
|||
|
|||
|
This is quite simple if your linked list has both head and tail pointers.
Please give a rough idea on the current implementation of the list. Then it becomes easy to come up with the solution. -------------- Programming (Assignment/Project) Help |
|
#3
|
|||
|
|||
|
I am a total newb so i have no idea what im doing. You could use a while loop to navigate to the end of the list, whereupon the pNext pointer becomes zero. Then change the pointers of the last object. current entry to begining of list pNDS->pNext = pHead
This may be no help at all and totally wrong. |
|
#4
|
||||
|
||||
|
The only way (I'm guessing) that the order of the linked list is kept is by pointers in each object that point to the next object in the list, is that how you're doing it?
If so, just set the pointer for the last element to point to the first element, and set the second-last element to point to 0.
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips. ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Linked List. Moving last number in the list to be the first one. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|