Friday, 11 April 2014

pollLast : Retrieves and removes the last element of this deque

E pollLast()
Retrieves and removes the last element of this deque.

import java.util.*;

class DequePollLast{
 public static void main(String args[]){
  Deque<Integer> myDeque = new LinkedList<Integer> ();
  
  /* Add Elements to the myDeque */
  myDeque.add(10);
  myDeque.add(20);
  myDeque.add(30);
  myDeque.add(40);
  
  System.out.println("Elements in the myDeque are " +myDeque);
  
  System.out.println("\nRemoving the Last Element Of the Deque " + myDeque.pollLast());
  System.out.println("Elements in the myDeque are " +myDeque);
  
  System.out.println("\nRemoving the Last Element Of the Deque " + myDeque.pollLast());
  System.out.println("Elements in the myDeque are " +myDeque);
  
  System.out.println("\nRemoving the Last Element Of the Deque " + myDeque.pollLast());
  System.out.println("Elements in the myDeque are " +myDeque);
  
  System.out.println("\nRemoving the Last Element Of the Deque " + myDeque.pollLast());
  System.out.println("Elements in the myDeque are " +myDeque);
  
 }
}

Output
Elements in the myDeque are [10, 20, 30, 40]

Removing the Last Element Of the Deque 40
Elements in the myDeque are [10, 20, 30]

Removing the Last Element Of the Deque 30
Elements in the myDeque are [10, 20]

Removing the Last Element Of the Deque 20
Elements in the myDeque are [10]

Removing the Last Element Of the Deque 10
Elements in the myDeque are []

1. return the tail of this deque, or null if this deque is empty
import java.util.*;

class DequePollLast{
 public static void main(String args[]){
  Deque<Integer> myDeque = new LinkedList<Integer> ();
  
  /* Add Elements to the myDeque */
  myDeque.add(10);
  myDeque.add(20);
  myDeque.add(30);
  myDeque.add(40);
  
  System.out.println("Elements in the myDeque are " +myDeque);
  
  System.out.println("\nRemoving the Last Element Of the Deque " + myDeque.pollLast());
  System.out.println("Elements in the myDeque are " +myDeque);
  
  System.out.println("\nRemoving the Last Element Of the Deque " + myDeque.pollLast());
  System.out.println("Elements in the myDeque are " +myDeque);
  
  System.out.println("\nRemoving the Last Element Of the Deque " + myDeque.pollLast());
  System.out.println("Elements in the myDeque are " +myDeque);
  
  System.out.println("\nRemoving the Last Element Of the Deque " + myDeque.pollLast());
  System.out.println("Elements in the myDeque are " +myDeque);
  
  System.out.println("\nRemoving the Last Element Of the Deque " + myDeque.pollLast());
  System.out.println("Elements in the myDeque are " +myDeque);
  
 }
}

Output
Elements in the myDeque are [10, 20, 30, 40]

Removing the Last Element Of the Deque 40
Elements in the myDeque are [10, 20, 30]

Removing the Last Element Of the Deque 30
Elements in the myDeque are [10, 20]

Removing the Last Element Of the Deque 20
Elements in the myDeque are [10]

Removing the Last Element Of the Deque 10
Elements in the myDeque are []

Removing the Last Element Of the Deque null
Elements in the myDeque are []


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment