-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsll_smallest.c
58 lines (52 loc) · 1.02 KB
/
sll_smallest.c
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
#include <stdio.h>
#include <stdlib.h>
int item;
char ch;
struct node
{
int data;
struct node *link;
} *head, *ptr, *new;
struct node *create_sll()
{
do
{
new = (struct node *)malloc(sizeof(struct node));
printf("Enter the data to be inserted : ");
scanf("%d", &item);
new->data = item;
new->link = NULL;
if (head == NULL)
{
head = new;
ptr = head;
}
else
{
ptr->link = new;
ptr = ptr->link;
}
printf("Do you want to enter a new node ?(y/n) : ");
scanf(" %c",&ch);
}while(ch=='y');
return head;
}
void find_smallest(struct node *head)
{
ptr = head;
int smallest = ptr->data;
while(ptr!=NULL)
{
if(ptr->data<smallest)
{
smallest = ptr->data;
}
ptr=ptr->link;
}
printf("The smallest element in the linked list is : %d\n",smallest);
}
void main()
{
head = create_sll();
find_smallest(head);
}