We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e56ebef commit a7d8861Copy full SHA for a7d8861
Test/Delete alternate nodes
@@ -0,0 +1,39 @@
1
+Given a Singly Linked List of integers, delete all the alternate nodes in the list.
2
+Example:
3
+List: 10 -> 20 -> 30 -> 40 -> 50 -> 60 -> null
4
+Alternate nodes will be: 20, 40, and 60.
5
+
6
+Hence after deleting, the list will be:
7
+Output: 10 -> 30 -> 50 -> null
8
9
10
+void delete_alternate_node_LinkedList(Node *head) {
11
12
+ if(head==NULL)
13
+ return;
14
+ if(head->next==NULL)
15
16
17
+ int x=length(head);
18
19
+ Node *p=head;
20
+ Node *q=head;
21
22
+ for(int i=2 ; i <x ; i=i+2)
23
+ { p=p->next;
24
+ Node *t=p;
25
+ p=p->next;
26
+ q->next=p;
27
+ delete t;
28
+ q=p;
29
+ }
30
31
+ if(x%2==0)
32
+ {
33
34
+ q->next=NULL;
35
+ delete p;
36
37
38
39
+}
0 commit comments