Solutions
HackerEarth
HackerEarth
  • Home
  • 👨🏻‍💻 Profile
  • Practice
    • Basic Programming
      • Input/Output
        • Easy
    • Data Structure
      • Linked List
    • Algorithms
      • Searching
        • Linear Search
        • Binary Search
      • Greedy Algorithms
Powered by GitBook
On this page

Was this helpful?

  1. Practice
  2. Data Structure

Linked List

PreviousData StructureNextAlgorithms

Last updated 2 years ago

Was this helpful?

Reversed Linked List

using System;
using System.Collections;
					
public class Program {
    public static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
	var input = Console.ReadLine().Split(" ");
	Stack evenStack = new Stack();
	for(int i = 0; i < n; i++) {
            var num = Convert.ToInt32(input[i]);
            if(num % 2 == 0) 
                evenStack.Push(num);
            else {
                while(evenStack.Count > 0) {
		    Console.Write(evenStack.Pop() + " ");
	        }
                Console.Write(num + " ");
            }
        }
	while(evenStack.Count > 0) {
            Console.Write(evenStack.Pop() + " ");
        }
    }
}
Reversed Linked List | Practice ProblemsHackerEarth
Logo