C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 15th, 2005, 11:34 AM
Robert1055 Robert1055 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 1 Robert1055 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 55 sec
Reputation Power: 0
Question Linked List. Moving last number in the list to be the first one.

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.

Reply With Quote
  #2  
Old August 18th, 2005, 12:43 PM
proghelper proghelper is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 12 proghelper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 46 m 21 sec
Reputation Power: 0
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

Reply With Quote
  #3  
Old August 18th, 2005, 01:27 PM
kolokol kolokol is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 18 kolokol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 3 m 5 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old August 18th, 2005, 03:45 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 1 m 43 sec
Reputation Power: 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.



Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Linked List. Moving last number in the list to be the first one.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway