1 / 9

public class DoubleLinkedNode{ private String info = new String();

Double Linked Node Class. public class DoubleLinkedNode{ private String info = new String(); private DoubleLinkedNode nextLeft = null; private DoubleLinkedNode nextRight = null; public DoubleLinkedNode(DoubleLinkedNode nextLeft, String info, DoubleLinkedNode nextRight){

liz
Télécharger la présentation

public class DoubleLinkedNode{ private String info = new String();

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Double Linked Node Class public class DoubleLinkedNode{ private String info = new String(); private DoubleLinkedNode nextLeft = null; private DoubleLinkedNode nextRight = null; public DoubleLinkedNode(DoubleLinkedNode nextLeft, String info, DoubleLinkedNode nextRight){ this.nextLeft = nextLeft; this.info = info; this.nextRight = nextRight; } public DoubleLinkedNode(String info){ this.nextLeft = null; this.info = info; this.nextRight = null; }

  2. Double Linked Node Class public void setNextRight(DoubleLinkedNode right){ this.nextRight = right; } public void setNextLeft(DoubleLinkedNode left){ this.nextLeft = left; } public DoubleLinkedNode getNextRight(){ return this.nextRight; } public DoubleLinkedNode getNextLeft(){ return this.nextLeft; }

  3. Double Linked Node Class public void setInfo (String newInfo){ this.info = newInfo; } public String getInfo(){ return this.info; } }

  4. Double Ended Queue Class import java.io.*; public class DoubleEndedQueue{ private DoubleLinkedNode leftmost; private DoubleLinkedNode rightmost; public DoubleEndedQueue (){ leftmost = null; rightmost = null; }

  5. Double Ended Queue Class public void addNodeLeft(DoubleLinkedNode DLNode){ if(leftmost == null){ leftmost = DLNode; rightmost = DLNode; } else{ leftmost.setNextLeft(DLNode); DLNode.setNextRight(leftmost); leftmost = DLNode; } }

  6. Double Ended Queue Class public void addNodeRight(DoubleLinkedNode DLNode){ if(rightmost == null){ rightmost = DLNode; leftmost = DLNode; } else{ rightmost.setNextRight(DLNode); DLNode.setNextLeft(rightmost); rightmost = DLNode; } }

  7. Double Ended Queue Class public void removeNodeLeft(){ if(leftmost!=null){ leftmost = leftmost.getNextRight(); leftmost.setNextLeft(null); } } public void removeNodeRight(){ if(rightmost!=null){ rightmost = rightmost.getNextLeft(); rightmost.setNextLeft(null); } }

  8. Double Ended Queue Class public String writeListRightLeft(){ String s = ""; DoubleLinkedNode cursor = rightmost; while(cursor != null){ s = (s+"\n "+(cursor.getInfo())); cursor = cursor.getNextLeft(); } return s; }

  9. Double Ended Queue Manager Class public class DEQmanager{ public static void main (String arg[ ]){ DoubleEndedQueue deq = new DoubleEndedQueue( ); int i = 0; for (i = 1; i<=5; i++){ deq.addNodeRight(new DoubleLinkedNode(""+ i)); } ///for System.out.println("printing left to right" ); System.out.println(deq.writeListLeftRight( )); System.out.println("printing right to left" ); System.out.println(deq.writeListRightLeft( )); }//end of main method } //end of class

More Related