0

import java.util.*;
public class MainAssignment3
{
public static void main(String[]args)
{
int Max =0;
int Value =0;

LinkedList<Integer>Input=new LinkedList<Integer>();
LinkedList<Integer>Temp=new LinkedList<Integer>();
LinkedList<Integer>OutPut=new LinkedList<Integer>();

Input.addLast(90);
Input.addLast(21);
Input.addLast(33);
Input.addLast(80);
Input.addLast(67);

System.out.println("The Input Stack is : " + Input);

while(!Input.isEmpty())
{
Max = (Integer)Input.removeLast();
Value = (Integer)Input.removeLast();

System.out.println("MAx: " +Max);
System.out.println("Value: " +Value);

if (Value < Max)
{
Temp.addLast(Max);
Max=Value;

} else {
Temp.addLast(Value);
}


Input = Temp;
OutPut.addLast(Max);
Temp.clear();
System.out.println(OutPut);

}
}
}

Input Stack should is [90, 21, 33, 80, 67]
OutPut Stack Should is [21, 33, 67, 80 ,90]
But i Only Get [67]
any solution help ?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by gangsta1903
0

Related to posting thread, have you heard about CODE TAGS?
Also can you please write a few sentences telling what you need and what you are trying to do.

Related to your problem, have you heard about DEBUGGING?
What do you think the following line does?? Input = Temp;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.