-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp1.c
53 lines (53 loc) · 1 KB
/
p1.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
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node* next;
};
struct node *head=NULL;
void create(int x){
struct node* newnode,*temp;
newnode=(struct node*)malloc(sizeof(struct node));
newnode->data=x;
newnode->next=NULL;
if(head==NULL){
head=newnode;
}
else{
temp=head;
while(temp->next!=head)
temp=temp->next;
temp->next=newnode;
}
newnode->next=head;
}
void delete(int x){
struct node* temp,*pnode;
int i=0;
while(i<x){
pnode=temp;
temp=temp->next;
i++;
}
pnode->next=temp->next;
free(temp);
}
void display(){
struct node* temp;
temp=head;
while(temp->next!=head){
printf("%d\t",temp->data);
temp=temp->next;
}printf("%d\n",temp->data);
printf("\n");
}
int main(){
int ch;
printf("1.Insert 2.Delete 3.Display 4.Exit\n");
create(4);
create(48);
create(12);
create(77);
delete(3);
display();
}