/**
* Exercise 4:
* write a Java application to insert THREE(3) integers 8, 10, 66 using insertAtFront().
* Print and observe the output.
* note: the output should be 66,10,8
*
* @author MUHAMMAD AZRI BIN JASNI
* @version 10 OCTOBER 2012
*/
import java.util.*;
public class exercise4
{
public static void main(String [] args)
{
LinkedList list = new LinkedList();
Scanner sc = new Scanner(System.in);
int input;
System.out.println("Enter the 3 integers[8,10,66] at the front.");
for (int i=0;i<3;i++)
{
input = sc.nextInt();
list.insertAtFront(input);
}
list.display();
/* Exercise 5
* Write the complete definition for method insertAtBack() and insert
* another THREE (3) integers 68, 3, 1. Print and observe the output.
* *Note: The output should be 66, 19, 8, 68, 3, 1*/
System.out.println("Enter the 3 integers[68,3,1] at the back.");
for (int i=0;i<3;i++)
{
input = sc.nextInt();
list.insertAtBack(input);
}
list.display();
/* Exercise 6
* Write the complete definition for method removeFromFront() and remove a node.
* Print and observe the output.
*
* *Note: The output should be 10, 8, 68, 3, 1*/
System.out.println("Removing an element from the front...");
list.removeFromFront();
list.display();
/* Exercise 7
* Write the complete definition for method removeFromBack() and remove
* TWO(2) nodes. Print and observe the output.
* *Note: The output should be 10, 8, 68*/
System.out.println("Removing 2 element from the back...");
list.removeFromBack();
list.display();
list.removeFromBack();
list.display();
sc.close();
}
}