Problem with my program...
my program has not work properly...
actually my program need to print the sorted numbers in linked list...
and my program not print a sorted numbers in linked list...
here is my code..please help me..
Code:
#include <stdio.h>
#include <stdlib.h>
# include<conio.h>
# include<malloc.h>
struct node
{
int data;
struct node *next;
};
void in_begin(struct node **,int);
void display(struct node *);
void SortAscending(void);
int iArray[4]={203,5,10,110};
void main()
{
int i;
printf("The original array is : ");
for(i=0;i<4;i++)
{
printf("| %d |",iArray[i]);
}
printf("\n");
SortAscending();
}
void SortAscending()
{
int i;
int j;
int temp;
int sorted_array;
struct node *p;
p=NULL;
printf("\n");
printf("Sorted Array");
for(i = 0; i < 4; i++)
{
for(j = i+1; j < 4; j++)
{
if(iArray[i] > iArray[j])
{
temp = iArray[i];
iArray[i] = iArray[j];
iArray[j] = temp;
}
}
printf("| %d |",iArray[i]);
}
printf("\n\n");
printf("The numbers has been sorted in Linked list like this : \n");
for (i=0;i<4;i++)
{
sorted_array=iArray[i];
in_begin(&p,sorted_array);
}
display(p);
}
void in_begin(struct node **q,int num)
{
struct node *temp;
if(*q==NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=*q;
*q=temp; /* pointing to the first node */
}
else
{
printf("Nothing");
getch();
goto last;
}
last:
getch();
}
void display(struct node *q)
{
if(q==NULL)
{
printf("\n\nEmpty Link List.Can't Display The Data");
getch();
goto last;
}
while(q!=NULL)
{
printf("\n%d",q->data);
q=q->next;
}
last:
getch();
}