Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Data File StructureRSS Feeds

Sorting link list

Posted By: Sara Hughes     Category: C Programming     Views: 7607

Write a program of sorting link list.

Code for Sorting link list in C Programming

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

struct sort
{
int info;
struct sort *link;
};

struct sort *start=NULL,*temp1;

void main()
{
int ch;
while(ch!=4)
  {
  clrscr();
  printf("1 for insert values\n");
  printf("2 for delete values\n");
  printf("3 for display\n");
  printf("4 for Exit\n");
  printf("\nEnter your choice: ");
  scanf("%d",&ch);
  switch(ch)
     {
     case 1:insert();break;
     case 2:delete_node();break;
     case 3:display();break;
     case 4:break;
     }
   }
}

insert()
{
struct sort*new;
new=(struct sort *)malloc(sizeof(struct sort));
printf("Enter Node Value: ");
scanf("%d",&new->info);
new->link=start;
start=new;
}
delete_node()
{
struct sort *temp;
temp=start->link;
start=temp;
}

display()
{
struct sort *temp;
printf("The node's information\n");
for(temp=start;temp!=NULL;temp=temp->link)
   {
   printf("%d\n",temp->info);
   }
printf("\nThe node's information After Sorting \n\n");
for(temp=start;temp!=NULL;temp=temp->link)
   {
     for(temp1=temp->link;temp1!=NULL;temp1=temp1->link)
       {
       if(temp->info > temp1->info)
           {
           int t=temp->info;
           temp->info=temp1->info;
           temp1->info=t;
           }
       }
   }

for(temp=start;temp!=NULL;temp=temp->link)
   {
   printf("%d\n",temp->info);
   }

getch();
}
  
Share: 


Didn't find what you were looking for? Find more on Sorting link list Or get search suggestion and latest updates.

Sara Hughes
Sara Hughes author of Sorting link list is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!