top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

can any one write the program for reverse the Linkedlist But I want output as below

+3 votes
651 views

input: 1 2 3 4 5
output: 5 4 1 2 3 or 1 2 3 5 4

Can any one tell?

posted Oct 9, 2013 by Giri Prasad

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
you can write but can not generalize; or give some more examples to understand what your are trying to do.
I have 5 nodes in that i want to reverse last 2 nodes and first 3 nodes as to display as it is(no need to reverse first 3 nodes).for that only i give some example as input and ouput in my question.
That's what the point traverse three node and after that apply reverse function on the rest of the link list it will give you 12354 but again that is a very particular case.

1 Answer

+4 votes

In these type of Question Its better to write recursive code use some counter.
You can count how many node you want to reversr.

You can see this as an example.

Code written by VIKAS UPADHYAY

I will post the code here Soon.

answer Oct 10, 2013 by Vikas Upadhyay
Similar Questions
+3 votes

Given a 2d array, u need to sort the 2 diagonals independently.
And the elements in diagonal should remain in diagonal only.

INPUT =>
24 2 3 4 7

6 13 8 5 10

11 12 9 14 15

16 21 18 25 20

17 22 23 24 1

OUTPUT =>
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

0 votes
#include<stdio.h>
main()
{
        int a=10;
        printf("%d\n",a++==a);
}

Output should be 1 but it is coming as 0,
Can anyone please explain?

...