Skip to content

Commit 697628b

Browse files
committed
changes in circular linked list deletion
1 parent 402e0ac commit 697628b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Linked List/Circular Linked List/operations.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,36 @@ void insertAfterPos(){
189189
}
190190

191191
void deletePos(){
192+
int x , i;
193+
struct Node *temp , *prev , *last;
194+
195+
printf("Enter the position to delete : ");
196+
scanf("%d" , &x);
197+
198+
temp = start;
199+
for( i = 1 ;i != x && temp->next != start ; i++){
200+
prev = temp;
201+
temp = temp->next;
202+
}
203+
204+
if(i != x){
205+
printf("value not found");
206+
return;
207+
}else if(temp == start){
208+
last = temp;
209+
while(last->next != start){
210+
last = last->next;
211+
}
212+
213+
start = temp->next;
214+
last->next = start;
215+
free(temp);
216+
}else {
217+
prev->next = temp->next;
218+
free(temp);
219+
}
220+
}
221+
192222
int x;
193223
struct Node *temp = start, *prev= NULL;
194224

0 commit comments

Comments
 (0)