Using ArrayDeque For constructing Stack in java .


following program show how to create simple stack in java.While executing this program you can feel real word of Stack FILO concept in real time
// Comment

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
packagecom.allinalljava;
importjava.util.*;
/**
 *
 * @author allinalljava
 */
public class JavaArrayDeque {


public static void main(String args[]) {
// Create a tree set.
ArrayDequeadq = new ArrayDeque();
// Use an ArrayDeque like a stack.
adq.push("A");
adq.push("B");
adq.push("D");
adq.push("E");
adq.push("F");
System.out.print("Popping the stack: ");
while(adq.peek() != null)
System.out.print(adq.pop() + " ");
System.out.println();
}
}

OutPut
Popping the stack: F E D B A
raja P Web Developer

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...