-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdelete a node in circlur linklist.cpp
116 lines (116 loc) · 2.43 KB
/
delete a node in circlur linklist.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
{
struct node *pre;
int info;
struct node *next;
}*new_node,*start,*last,*temp;
void create()
{
int value,choice;
do{
new_node=(struct node*)malloc(sizeof(struct node));
printf("Enter element : ");
scanf("%d",&value);
new_node->pre=NULL;
new_node->info=value;
new_node->next=NULL;
if(start==NULL)
{
start=new_node;
last=new_node;
}
else
{
last->next=new_node;
new_node->pre=last;
last=new_node;
}
printf("Wnat to add more for 1\0");
scanf("%d",&choice);
}while(choice);
}
void display()
{
printf("your linklist in right direction : ");
printf("NULL<->");
temp=start;
while(temp->next!=NULL)
{
printf("%d<->",temp->info);
temp=temp->next;
}
printf("%d<->",temp->info);
printf("NULL\n");
printf("your linklist in left direction : ");
printf("NULL<->");
temp=last;
while(temp->pre!=NULL)
{
printf("%d<->",temp->info);
temp=temp->pre;
}
printf("%d<->",temp->info);
printf("NULL");
}
void deletenode()
{
int choice,pos,i;
printf("***choice***\n1.delete at beg\n2. delete at end\n3. delete at specfic postion\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
new_node=(struct node*)malloc(sizeof(struct node));
if(new_node==NULL)
{
printf("out of memory\n");
exit(1);
}
temp=start;
start=temp->link;
temp->link=NULL;
break;
case 2:
new_node=(struct node*)malloc(sizeof(struct node));
if(new_node==NULL)
{
printf("out of memory\n");
exit(1);
}
temp=start;
while(temp->link!=last)
{
temp=temp->link;
}
temp->link=NULL;
last=temp;
break;
case 3:
new_node=(struct node*)malloc(sizeof(struct node));
printf("\nEnter postion : ");
scanf("%d",&pos);
if(new_node==NULL)
{
printf("out of memory\n");
exit(1);
}
temp=start;
for(i=0;i<pos-1;i++)
{
temp=temp->link;
}
temp=temp->link;
temp->link=temp->link->link;
break;
default:
printf("wrong choice\n ");
}
}
int main()
{
create();
display();
}