Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DLSList {
- // Class invariant: The nodes in the list are sorted (ascending) according to the contents
- // AND numNodes == the number of nodes in the list
- // AND (lastVisited points to the node which was last valid access after method visit is called
- // OR is set to head (in case removeNode demands it) or it is initialised)
- DNode head; // The first node in the list
- DNode lastVisited; // The address of the node last visited
- int numNodes; // The number of nodes in the list
- DLSList (){
- head= null;
- lastVisited= null;
- numNodes= 0;
- }
- void addNewNode(DNode newNode) { //TODO
- // Post: newNode is inserted into the current list in correct sorted order
- // numNodes is adjusted to be equal to the number of nodes in the list
- ArrayList<String> ar = new ArrayList<String>();
- lastVisited = head;
- for (int i = 0; i < numNodes; i++){
- System.console().printf(lastVisited.contents); //This is Null!?
- ar.add(lastVisited.contents);
- lastVisited = lastVisited.next;
- }
- lastVisited = head; //reset to head - start setting the values
- ar.add(newNode.contents);
- Collections.sort(ar);
- numNodes = ar.size()+1;
- }
- }
Add Comment
Please, Sign In to add comment