i am trying to move the node in the first item from the list and add it to the back of the list
1->2->3 becames 2->3->1
instead i get 3 1 2
#include <iostream>
using namespace std;
struct nodeType
{
int info;
nodeType *link;
};
void createList(nodeType*& first, nodeType*& last);
void printList(nodeType*& first);
void moveFront2Back(nodeType*& first, nodeType*& last);
int main()
{
nodeType *first, *last;
int num;
createList(first, last);
printList(first);
moveFront2Back(first,last);
system("PAUSE");
return 0;
}
void createList(nodeType*& first, nodeType*& last)
{
int number;
nodeType *newNode;
first = NULL;
last = NULL;
cout<<"Enter an integer (-999 to stop): ";
cin>>number;
cout<<endl;
while (number != -999)
{
newNode = new nodeType; // create new node
newNode->info = number;
newNode->link = NULL;
if (first == NULL)
{
first = newNode;
last = newNode;
}
else
{
last->link = newNode;
last = newNode;
}
cout<<"Enter an integer (-999 to stop): ";
cin>>number;
cout<<endl;
} // end of while-loop
} // end of build list function
void printList(nodeType*& first)
{
cout<<"Inside printList...printing linked list...\n"<<endl;
nodeType *current;
current = first;
while (current != NULL)
{
cout << current->info<<endl;
current = current->link;
}
}
void moveFront2Back(nodeType*& first, nodeType*& last)
{
nodeType* current;
if(first!=NULL)
{
if(first->link!=NULL)
{
current=first;
while (current->link!=last)
current=current->link;
current->link=NULL;
last->link=first;
first=last;
last=current;
}
}
printList(first);
}