• 12-02-2001
Unregistered
I have created a simple linked list that contains an unordered list of integers.

i.e. 5, 4, 3, 2, UN-ordered

The problem is, after I have sorted them,

to 2, 3, 4, 5 ORDERED

the the original header node which was 5 is now 2
and so lose the original unordered list in the process.

I know I'm destroying the original header pointer, cannot figure out how to keep from doing so!

Question: How do I go about keeping both the unordered and ordered linked lists ?

/*The sortOnode Function below sorts an unordered linked list of integers referenced by the oldheader parameter. It points to the first node of the unordered linked list . Unfortunately, after it has sorted the integers the original unordered list is deleted and all that remains is the new Ordered linked list.
How do keep track of the unordered linked list*/

Here's what I got so far!

{

int swap = 1;
int temp;

nodePtrType prevptr, curptr;

while (swap > 0 )
{
swap = 0;

while (curptr!= NULL)
{

if ( curptr->nnum > prevptr->nnum)
{
prevptr = curptr;

} //end of while loop

else

{

temp = prevptr->nnum;

prevptr->nnum= curptr->nnum;
curptr->nnum= temp;
prevptr = curptr;
swap = 1;

}//end else

}//end while curptr!= 0

prevptr =NULL;

prevptr = curptr;

}//end while swap >0 ;

} // end SortOnode
• 12-02-2001
Unregistered
the original and the ordered one
• 12-02-2001
Unregistered
or you could add an extra pointer in the node to keep track of the original thing it pointed to.
then you'd have one linked list
node
-value
-next node
-original node

sort of like a double linked list