By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

sorting in link list

P: 7
Question is :
Write a program making use of link list class
-create a class for details of staff( name ,surname and registration number)
-sort each staff according to registration number {***im having a problem with this part}

please help...
Sep 28 '06 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
Sorting is relatively easy. Sort the list entries as you add them to the list. Rather than add the new item at the head of the list search down the list to find the item you want to add the new entry after then

newEntry->next = currentEntry->next
currentEntry->next = newEntry

You will need a special case to handle needing to add the new entry at the head of the list (an alternitive to a special case is to uses pointers to pointers but I find a special case easier to read and understand)..
Sep 28 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.