PuzzlersWorld.com

  • Hacker Puzzle
  • Interview Puzzles
  • Number Puzzles
  • Maths Puzzles

Reverse a link list without using another

(1 votes, average: 1.00 out of 5)

November 12, 2012 by asinghal 2 Comments

How to reverse a link list without using another link list?

Note: Linked list is singly linked list (there is only next pointer no previous pointer).
See Solution: Reverse a link list without using another linked listHide Solution

Take two pointers previous and current, increment both pointers by one till current reaches at the end of the list.

Reverse a Linked List

Reverse a Linked List

Node* reverse(Node* node)
{
	if(node == null)
		return null;
	Node * prev = node;
	Node* curr = node->next;
	
	while(curr != null){
		Node* tmp = curr->next;
		curr->next = prev;
		prev = curr;
		curr = temp;
	}
	return prev;
}
  • Share on Whatsapp
  • Share on Facebook
  • Share on Twitter
Facebook Comments
Next Puzzle
Rotate an array by k elements

Checkout more Interview Questions Tags: Interview, Linked List, medium, Solved Puzzles

Comments

  1. Rahul says

    December 26, 2012 at 8:08 pm

    awsum logic for reverse a linklist ..thankss

    Reply
    • puzzlersworld says

      December 30, 2012 at 2:11 pm

      Thanks Rahul

      Reply

Leave a Comment Cancel reply

Submit your Puzzle

You may also like

  • Osmos Solution: Google codejam 2013 Round 1B
  • Lawnmower Solution: Google codejam 2013 Qual Round
  • Manage Your Energey Solution: Google codejam 2013 Round 1A
  • Charging Chaos Solution – Google CodeJam
  • Objective Questions set C/C++ – Part 5
  • Falling Diamonds Solution: Google codejam 2013 Round 1B
  • Subjective Question set C/C++ – Part 1
  • Find nth element from end of linked list
  • Cookie Clicker Alpha Solution – Google Code Jam 2014
  • Objective Questions set C/C++ – Part 2

Categories

  • Aive hi Puzzles
  • Akbar and Birbal
  • Alphabetical Puzzles
  • Bollywood Puzzles
  • Google Code jam
  • Hindi Riddles
  • Interview Puzzles
  • Interview Questions
  • Logical Puzzles
  • Malayalam Puzzles
  • Maths Puzzles
  • Miscellaneous
  • Number Puzzles
  • Picture Puzzles
  • Riddles
  • Tamil Puzzles
  • Technical

Social

  • View puzzlersworld’s profile on Twitter
privacy policy

Copyright © 2025 · eleven40 Pro Theme on Genesis Framework · WordPress · Log in

  • Hacker Puzzle
  • Logo Puzzles
  • Optical Illusions
  • WhatsApp Puzzles
  • Picture Puzzles
  • Riddles
    ▼
    • Hindi Riddles
  • Bollywood Puzzles
  • Alphabetical Puzzles
  • Aive hi Puzzles
  • Interview Puzzles
  • Logical Puzzles
  • Interview Questions
    ▲
    • Data Structures
    • Binary Tree
    • Algorithms
    • Recursion Questions
    • Amazon Interview Questions
    • Snapdeal Interview Questions
    • Google Code jam
  • Technical
  • Akbar and Birbal
  • Number Puzzles
  • Maths Puzzles
  • Miscellaneous