×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Reverse The Link List Elements - Link List in C Create a Circular Singly linked list
Sort the List Elements - Link List in C - Link list - C Language
680    Arnab De    13/09/2019

Sorting the elements of the linear linklist can in two types

  1. Ascending Order
  2. Descending Order
softetechnologies

Now we create the basic environment of the linklist.

#include<stdio.h>
#include<conio.h>
struct slinearlinklist
{
	int i;
	struct slinearlinklist *next;
};
typedef struct slinearlinklist node;

//prototype declaration
void *sort_data1(node *);
void *sort_data2(node *);

node *head=NULL;

int main()
{
	int c,i,pos;
	while(1)
	{
		printf(" 1. Ascending Order\n");
		printf(" 2. Descending Order\n");
		printf("25. Exit\n");
		printf("Enter Your choice : ");
		scanf("%d",&c);
		switch(c)
		{

			case 1:
				sort_data1(head); // Ascending Order
				break;
			case 2:
				sort_data2(head); // Descending Order
				break;
			
			case 25:
				exit(0);
		}
	}
}

Ascending Order

void *sort_data1(node *l)
{  
	node *temp1,*temp2;
	int x;
	temp1=l;
	while(temp1->next!=NULL)
	{
		for(temp2=temp1->next;temp2!=NULL;temp2=temp2->next)
		{
			if(temp1->i>temp2->i)
			{
				x=temp1->i;
				temp1->i=temp2->i;
				temp2->i=x;
			}
		}
		temp1=temp1->next;
	}
}
softetechnologies

Descending Order

void *sort_data2(node *l)
{  
	node *temp1,*temp2;
	int x;
	temp1=l;
	while(temp1->next!=NULL)
	{
		for(temp2=temp1->next;temp2!=NULL;temp2=temp2->next)
		{
			if(temp1->i<temp2->i)
			{
				x=temp1->i;
				temp1->i=temp2->i;
				temp2->i=x;
			}
		}
		temp1=temp1->next;
	}
}
Reverse The Link List Elements - Link List in C Create a Circular Singly linked list
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Swami Vivekananda
If the poor cannot come to education, education must reach them, at the plough, in the bakery factor
Swami Vivekananda
2758
34.21
Today So Far
Total View (Lakh)
softetechnologies
01/01/2018     33611
28/06/2017     29530
02/08/2017     27024
26/05/2018     26987
15/05/2017     23239
06/07/2017     21773
01/08/2017     21320
25/06/2018     20153
21/04/2018     18620
14/07/2017     16471
softetechnologies