Create sorted linked list

Mar 12, 2012 at 7:50am
Anyone tell me what is meaning of following definition?
Write a program to create a sorted singly linked list.

is it when we create node at that time node will be in sorted order or after creating linked list sorting will be performed on list?
Mar 12, 2012 at 9:20am
means whenever you add a node the linked list, the resulting linked list will always be sorted. Thus nodes should be inserted in sorted order.
Mar 13, 2012 at 8:29am
k thanks can you give me logic for that?
i have tried but can't perform sorting
i have write code but not proper can you suggest me?
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
void create (int num)
{
	struct list *temp,*current;
	if(start==NULL) //for first node
	{
		temp=(struct list*)malloc(sizeof(struct list));
		temp->data=num;
		temp->next=NULL;
		start=temp;
	}
	else
	{
	current=start;
	while(current!=NULL)
	{
		if(current->next->data>num)
		{
			temp=(struct list*)malloc(sizeof(struct list));
			temp->data=num;
			temp->next=current->next;
			current->next=temp;
			return;
		}
		current=current->next;
	}
}
Last edited on Mar 13, 2012 at 8:42am
Topic archived. No new replies allowed.