-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSLL.c
More file actions
79 lines (72 loc) · 1.33 KB
/
SLL.c
File metadata and controls
79 lines (72 loc) · 1.33 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<stdio.h>
#include<stdlib.h>
struct nodes
{
char info;
struct nodes *next;
};
void create();
void print_list();
typedef struct nodes snodes;
snodes *head,*x,*y;
int nodes=0,j,k=0;
char a[20];
void main()
{
int ch;
while(1)
{
printf("Enter your choice:\n 1.Create circular list\n2.Print_list\n3.Palindrome Check\n4.Exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
create();
break;
case 2:
print_list();
break;
case 3:
palin();
break;
default:
exit(0);
}
}
}
//Function to create a x circular linked list
void create()
{
int i;
nodes=1;
x=(snodes*)malloc(sizeof(snodes));
printf("Enter data:");
scanf(" %c",&(x->info));
/*The %c conversion specifier won't automatically skip any leading whitespace, so if there's a stray newline in the input stream (from a previous entry, for example) the scanf call will consume it immediately. scanf(" %c", &c);*/
x->next=NULL; //CLL
head=x;
printf("If you wish to continue press 1 else 0:");
scanf("%d",&i);
while(i)
{
y=(snodes*)malloc(sizeof(snodes));
nodes++;
printf("Enter data:");
scanf(" %c",&y->info);
x->next=y;
y->next=NULL;
x=y;
printf("If you wish to continue,press 1 ,else 0:");
scanf("%d",&i);
}
}
void print_list()
{
x=head;
while(x!=NULL)
{
printf("%c\n",x->info);
x=x->next;
}
printf("%d\n",nodes);
}