Thursday, August 26, 2010

LinkLists in C++: Part 4

Fourth in the series of Link-List funtions.

/***************************************************/
#include< iostream.h >
#include< conio.h >
#include< stdlib.h >

struct node
{
int info;
node* next;
}*start, *end, *t;

void reverse()
{
int n;
t = start;
while(t != NULL)
{
n++;
t = t->next;
}
for(int i = 0;i <= n-3;i++)
{
t = start;
while(t->next->next->next != NULL)
t = t->next;
t->next->next->next = t->next;
t->next->next = NULL;
}
t = start;
t->next->next = start;
t->next = NULL;
t1 = start;
start = end;
end = t1;
}

void sort()
{
t = start;
while(t != NULL)
{
t1 = start;
while(t1 != NULL)
{
if(t1->next->info > t1->next->next->info)
{
t1->next = t1->next->next;
t1->next->next = t1->next->next->next;
t1->next->next->next = t1->next;
}
t1 = t1->next;
}
t = t->next
}
}

No comments:

Post a Comment