3,151 views

2 Answers

Best answer
4 4 votes

This  code results in the printing of elements alternatively in linked list

suppose 10 || ----> 20 || ------> 30 || ------> 40 || -------> 50 || NULL

prints(10)        head->next->next ------->3rd node

prints(30)        head->next->next ------->5th node

prints(50)        here head->next is null prints(50) and again moves back prints results in reverse

10 30 50 50 30 10


if(head == null)  ---------------- if head is null nothing is done

 return



 

• edited by
4 4 votes

First printf will print alternate elements from start to last 

Second printf will print in reverse order , same data which was printed by first printf .

• edited by
Position:
Show:

Related questions

0 0 votes
2 2 answers
1.0k
1.0k views
Akash Mishra asked Jul 7, 2017
1,030 views
What is the value of F(n, m)?Function F(n, m : integer) : integer; begin if(n <= 0) or (m <= 0) then F:=1 else F := F(n-1, m) + F(n, m-1); end;
0 0 votes
1 1 answer
1.3k
1.3k views
Ahsanul Hoque asked Mar 6, 2018
1,302 views
Can anyone check this program?I got some warning.#include<stdio.h>#include<stdlib.h>void func(struct node *); struct node{ int data; struct node *next;}; int ...
8 8 votes
3 3 answers
260
260 views
GO Classes asked Jun 8
260 views
What is the output of the following code?#include <stdio.h int fun(int n) { if (n <= 1) return n; return fun(n - 1) + fun(n - 3); } int main() { printf("%d", fun(5)); ret...
6 6 votes
4 4 answers
897
897 views
GO Classes asked Jun 28, 2025
897 views
Consider the following recursive C function.unsigned int f(unsigned int n) { if (n < 10) printf("%d",n); else { printf("%d", n%10); f(n/10); printf("%d", n%10); } }What d...