Creating a linked list while sorting it
Oh man! This stuff is giving me a headache! The concept is so simple, but I just can't seem to write the code. Can someone please show me how?
void createlistKB(Node * &First)
{
int NewID = 0;
cout << "Please Input Your List:\n";
cout << "Enter -999 to stop\n";
cout << "-----------------------\n";
Node *Temp1, *Temp2, *NewNode;
First = new Node;
cin >> First->ID;
First->Next=NULL;
Temp1 = First;
Temp2 = Temp1;
do
{
NewNode = new Node;
cin >> NewID;
if(NewID != -999)
{
NewNode->ID = NewID;
cout << First->Next;
if(NewNode->ID < First->ID)
{
NewNode->Next = First;
First = NewNode;
cout << First->Next->Next;
}
do
{
if(NewNode->ID < Temp1->ID)
{
Temp2->Next = NewNode;
NewNode->Next = Temp1;
}
Temp2 = Temp1;
Temp1 = Temp1->Next;
cout << Temp1->Next;
}while(Temp1->Next != NULL);
}
}while(NewID != -999);
cout << "THANK YOU!!!\n\n";
}
that's the junk i have so far, i can't seem to figure it out...
here is the Node:
struct Node
{
int ID;
Node *Next;
};