-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCOWSCLLAsgnQ2.c
More file actions
65 lines (57 loc) · 979 Bytes
/
COWSCLLAsgnQ2.c
File metadata and controls
65 lines (57 loc) · 979 Bytes
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
//Q.2 Create a CLL take input from users.
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* next;
};
struct node* newNode(int val)
{
struct node* ptr = (struct node*)malloc(sizeof(struct node));
ptr->data = val;
ptr->next = NULL;
return ptr;
}
void viewList(struct node* Head, int n)
{
printf("\nCircular Linked List : ");
struct node* temp = Head;
for(int i=0;i<n+2;i++)
{
printf("%d\t",temp->data);
temp = temp->next;
}
printf("...");
}
void CircularLinkedList()
{
struct node* Head = NULL;
struct node* temp;
printf("How many nodes do want to insert ? ");
int n;
scanf("%d",&n);
printf("Enter the %d values you want to insert : ",n);
for(int i=0;i<n;i++)
{
int val;
scanf("%d",&val);
if(Head == NULL)
{
temp = newNode(val);
Head = temp;
}
else
{
temp->next = newNode(val);
temp = temp->next;
}
}
temp->next = Head;
viewList(Head, n);
}
int main()
{
CircularLinkedList();
return 0;
}