forked from WebClub-NITK/Hacktoberfest-2k17
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircular.c
More file actions
77 lines (77 loc) · 1.36 KB
/
Copy pathcircular.c
File metadata and controls
77 lines (77 loc) · 1.36 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
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int data;
struct Node *next;
};
typedef struct Node node;
void insert(struct Node** head, int key)
{
struct Node *newnode =(struct Node*)malloc(sizeof(struct Node));
newnode->data = key;
if(*head==NULL)
{
*head=newnode;
}
else
{
newnode->next = *head;
*head=newnode;
}
node* temp=*head;
while(temp!=NULL)
temp=temp->next;
temp->next=*head;
return;
}
void traverse(node* head)
{
node* temp=head;
printf("%d",head->data);
temp=temp->next;
while(temp!=head)
{
printf("%d",temp->data);
temp=temp->next;
}
printf("\n");
}
int main()
{
struct Node *head = NULL;
int t=1;
while(t)
{
printf("Choose from menu\n");
printf("1. Insert node at beginning\n");
printf("3. Delete node of given value \n");
printf("4. Print list\n");
printf("5. Exit\n");
int choice;
scanf("%d",&choice);
if(choice==1)
{
printf("Enter data\n");
int d;
scanf("%d",&d);
insert(&head,d);
}
else if(choice==3)
{
printf("Enter value to delete\n");
int d;
scanf("%d",&d);
}
else if(choice==4)
{
printf("List is\n");
traverse(head);
}
else
{
t=0;
}
}
return 0;
}