I am a little new at this (notice the name )
I created a linked list and want to sort it (notice thread name )
Here is my linked list:
Code:
struct NODE
{
int data;
NODE *next;
};
class LINKED_LIST
{
public:
LINKED_LIST();
~LINKED_LIST();
void insertAfterHead(int);
int getHead() { return head->data; }
int getTail() { return tail->data; }
int printList();
bool searchList(int);
void clear();
void removeNode(int);
NODE *head;
NODE *tail;
};
Here is my sorting method:
Code:
LINKED_LIST sortList(LINKED_LIST List)
{
LINKED_LIST Temp;
NODE *walker = new NODE, *temp_node = new NODE;
int a = 0,b = 0;
walker = List.head;
temp_node->data = 1;
while(walker != NULL)
{
if(walker->data > temp_node->data)
temp_node = walker;
walker = walker->next;
if(walker->next == NULL)
{
Temp.insertAfterHead(temp_node->data);
delete temp_node;
walker = List.head;
NODE *temp_node = new NODE;
temp_node->data = 1;
}
}
return List;
}
And I have double checked it and didn't see anything wrong with it, but I make many mistakes in debugging and no idea what is wrong, perhaps some help can be offered