Advertisement
Advertisement
| 04.16.2008 at 11:34PM PDT, ID: 23329913 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: |
#include <stdio.h>
#include <stdlib.h>
struct Node {
int DATA;
struct Node *Next;
} *Head, *Curr;
void List_Init(void);
void Fill_List(struct Node **Add, int Rand);
void Sort_List(void);
void Print_List(void);
#define MAX 100
int main()
{
List_Init();
Sort_List();
Print_List();
}
void List_Init(void)
{
struct Node *Add_node = NULL;
int i = 0;
for(i = 0; i < MAX; i++)
{
Fill_List(&Add_node, (rand() % 100));
}
Head = Add_node;
}
void Fill_List(struct Node **Add, int Rand)
{
struct Node *Temp;
Temp = *Add;
if (*Add == NULL)
{
*Add = malloc(sizeof(struct Node));
Temp = *Add;
}
while (Temp->Next != NULL)
{
Temp = Temp->Next;
Temp->Next = malloc(sizeof(struct Node));
Temp = Temp->Next;
}
Temp->DATA = Rand;
Temp->Next = NULL;
}
void Sort_List(void)
{
int abc;
struct Node* temp;
struct Node* again=Head;
while (again)
{
while(temp->Next)
{
if(Head->DATA < temp->DATA)
{
abc = Head->DATA;
Head->DATA = temp->DATA;
temp->DATA = abc;
}
Head = Head->Next;
temp = temp->Next;
}
temp = Head;
Head = temp->Next;
again=again->Next;
}
//temp=high;
//temp=head->next;
temp = Head;
}
void Print_List(void)
{
Curr = Head;
while (Curr != NULL)
{
printf("%d ", Curr->DATA);
Curr=Curr->Next;
}
printf("\n");
}
|