John Delmark Aguilar

Delmark - Profiling
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in

Share | 
 

 Linked List Java Program

View previous topic View next topic Go down 
AuthorMessage
dElmARk
Admin
Admin
avatar

Posts : 92
Join date : 09/04/2012

PostSubject: Linked List Java Program   Tue Oct 23, 2012 10:28 am



LinkedList Syntax:
 
Back to top Go down
View user profile http://delmark.meabout.com
dElmARk
Admin
Admin
avatar

Posts : 92
Join date : 09/04/2012

PostSubject: Re: Linked List Java Program   Tue Oct 23, 2012 1:10 pm

Code:

import java.util.*;
class LLS{
  public static void main(String [] ecs){
    LinkedList LLL = new LinkedList();
    Scanner sc=new Scanner(System.in);
    System.out.println("LinkedList Elements " + LLL);
    System.out.println("Enter an Option\n1 - AddFirst\t2 - AddLast\t3 - Add @ specified index\t4 - RemoveFirst\n\t5 - RemoveLast\t6 - Remove @ specified index\t7 - exit");
   
    int ch = 0;
    int elem = 0;
    int ind = 0;
   
    do{
      System.out.print("Choice: ");
      ch = sc.nextInt();
      if(ch==1){
       
        System.out.print("Enter element to add\n");
        elem = sc.nextInt();
        LLL.addFirst(elem);
      }
      if(ch==2){
        System.out.print("Enter element to add\n");
        elem = sc.nextInt();
        LLL.addLast(elem);
      }
      if(ch==3){
        System.out.print("Enter index: ");
        ind = sc.nextInt();
        System.out.print("Enter element: ");
        elem = sc.nextInt();
        LLL.add(ind,elem);
      }
      if(ch==4){
        LLL.removeFirst(); 
      };
      if(ch==5){
        LLL.removeLast();
      }
      if(ch==6){
        System.out.print("Enter index: ");
        ind = sc.nextInt();
        LLL.remove(ind);
      }
      System.out.println("LinkedList Elements " + LLL); 
     
    }while(ch!=7);
  }
}
Back to top Go down
View user profile http://delmark.meabout.com
 
Linked List Java Program
View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
John Delmark Aguilar :: dElmARk Productions :: Java Programs :: Tutorials-
Jump to: