To add to the Application class:

 

/***************************************************************************/

/**************************** STACK ***********************************/

/***************************************************************************/

 

Stack stk = new Stack("Stack Example");

stk.pop();

/*

========================

Stack is empty; cannot pop

*/

 

stud = new Student("Ahmed Awal");

stk.push(stud);

stud = new Student("Ahmed Thani");

stk.push(stud);

stk.displayStack();

/*

========================

Student name: Ahmed Thani

 

Student name: Ahmed Awal

 

*/

 

stud = stk.peek();

System.out.println("========================");

System.out.println(stud.getName());

stk.displayStack();

/*

========================

Ahmed Thani

========================

Student name: Ahmed Thani

 

Student name: Ahmed Awal

 

*/

 

stud = stk.pop();

System.out.println("========================");

System.out.println(stud.getName());

stk.displayStack();

/*

========================

Ahmed Thani

 

========================

Student name: Ahmed Awal

 

*/

 

stud = new Student("Ahmed Thaleth");

stk.push(stud);

stk.displayStack();

/*

========================

Student name: Ahmed Thaleth

 

Student name: Ahmed Awal

 

*/

 

stk.pop();

stk.pop();

stk.displayStack();

/*

The list is empty

*/

 

/***************************************************************************/

 

/**************************** QUEUE ***********************************/

 

/***************************************************************************/

 

Queue q = new Queue("Queue Example");

q.dequeue();

/*

========================

Queue is empty; cannot dequeue

*/

 

stud = new Student("Ali Awal");

q.enqueue(stud);

stud = new Student("Ali Thani");

q.enqueue(stud);

q.displayQueue();

/*

========================

Student name: Ali Awal

 

Student name: Ali Thani

 

*/

 

stud = q.dequeue();

System.out.println("========================");

System.out.println(stud.getName());

q.displayQueue();

/*

========================

Ali Awal

 

 

========================

Student name: Ali Thani

 

*/

 

stud = new Student("Ali Thaleth");

q.enqueue(stud);

q.displayQueue();

/*

========================

Student name: Ali Thani

 

Student name: Ali Thaleth

 

*/

 

q.dequeue();

q.dequeue();

q.displayQueue();

/*

The list is empty

*/

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

 

 

public class Stack extends List

{

public Stack(String nm)

{

super(nm);// the stack's name

 

}

public void push(Student st)

{

insertAtFront(st);

}

public Student pop()

{

if (isEmpty())

{

System.out.println("\n\n========================");

System.out.println("Stack is empty; cannot pop");

return null;

}

return removeFromFront();

}

public Student peek()

{

if (isEmpty())

{

System.out.println("\n\n========================");

System.out.println("Stack is empty; cannot peek");

return null;

}

return getFirstNode().getData();

}

public void displayStack()

{

displayListContent();

}

}

 

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

public class Queue extends List

{

public Queue(String nm)

{

super(nm);// the stack's name

 

}

public void enqueue(Student st)

{

insertAtBack(st);

}

public Student dequeue()

{

if (isEmpty())

{

System.out.println("\n\n========================");

System.out.println("Queue is empty; cannot dequeue");

return null;

}

return removeFromFront();

}

public void displayQueue()

{

displayListContent();

}

}