@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public ListNode<Key, Value> readPayload(DataInput is) throws IOException { ListNode<Key, Value> node = new ListNode<Key, Value>(); node.setNext(is.readLong()); final short size = is.readShort(); for (short i = 0; i < size; i++) { node.entries.addLast(new KeyValueEntry(keyMarshaller.readPayload(is), valueMarshaller.readPayload(is))); } return node; } }
private void split(Transaction tx, boolean isAddFirst) throws IOException { ListNode<Key, Value> extension = getContainingList().createNode(tx); if (isAddFirst) { // head keeps the first entry, insert extension with the rest extension.setEntries(entries.getHead().splitAfter()); extension.setNext(this.getNext()); extension.store(tx, isAddFirst); this.setNext(extension.getPageId()); } else { extension.setEntries(entries.getTail().getPrevious().splitAfter()); extension.setNext(this.getNext()); extension.store(tx, isAddFirst); getContainingList().setTailPageId(extension.getPageId()); this.setNext(extension.getPageId()); } store(tx, true); }
static ListNode ReverseLinkedList(ListNode headNode) { ListNode headNodeTemp = headNode; headNodeTemp.setNext(null);
if (k == 0) { removedObject = this.removeFromFront(); } else { ListNode prev = null; while (idx != k) { prev = removedNode; removedNode = removedNode.getNext(); idx++; if (removedNode == null) throw new ListIndexOutOfBound(); } if (removedNode == this.lastNode) { removedNode = (ListNode) this.removeFromBack(); } else { removedObject = removedNode.data; prev.setNext(removedNode.getNext()); } }
static ListNode ReverseLinkedList(ListNode headNode) { ListNode headNodeTemp = headNode; ListNode tempNode = headNode.getNext(); headNodeTemp.setNext(null); ListNode currentNode = headNodeTemp; while(tempNode != null) {...
//when instantiated, MagazineList's list variable is set to null public void add (Magazine mag) { ListNode node = new ListNode (mag, null); ListNode current; if (list == null) list = node; else { current = list; // you list head while (node.compareTo(current) < 0) current = current.getNext(); ListNode next = current.getNext(); current.setNext(node); node.setNext(next); } }
public void addToBack(ListNode current, ListNode newNode) { //generic method that adds the node at the end ListNode nx = current.getNext(); if(nx == null) {//base case: current is the last node current.setNext(newNode); } else {//recursive case, current is not the next node addToBack(nx,newNode); } }
ListNode node1, node2; node1 = new ListNode("Fred",null); node2 = new ListNode("Charlie",null); node1.setNext(node2);
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public ListNode<Key, Value> readPayload(DataInput is) throws IOException { ListNode<Key, Value> node = new ListNode<Key, Value>(); node.setNext(is.readLong()); final short size = is.readShort(); for (short i = 0; i < size; i++) { node.entries.addLast(new KeyValueEntry(keyMarshaller.readPayload(is), valueMarshaller.readPayload(is))); } return node; } }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public ListNode<Key, Value> readPayload(DataInput is) throws IOException { ListNode<Key, Value> node = new ListNode<Key, Value>(); node.setNext(is.readLong()); final short size = is.readShort(); for (short i = 0; i < size; i++) { node.entries.addLast(new KeyValueEntry(keyMarshaller.readPayload(is), valueMarshaller.readPayload(is))); } return node; } }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public ListNode<Key, Value> readPayload(DataInput is) throws IOException { ListNode<Key, Value> node = new ListNode<Key, Value>(); node.setNext(is.readLong()); final short size = is.readShort(); for (short i = 0; i < size; i++) { node.entries.addLast(new KeyValueEntry(keyMarshaller.readPayload(is), valueMarshaller.readPayload(is))); } return node; } }
public void doRemove(int index, int size) { int listCount =1; ListNode temp = head; ListNode previous = head; for(int i=0;temp.getnext()!=null;i++) { listCount++; if(!(listCount == index)) { previous = temp; temp = temp.getNext(); } else { previous.setNext(temp.getNext()); } } }
if (head.getNext() == null) { head.setNext(new ListNode(myTrain)); count++; } else if (head.getNext().getTrain().getTrainNumber() < myTrain.getTrainNumber()) { newNode.setNext(head.getNext()); head.setNext(newNode); count++; } else { currentNode.setNext(currentNode.getNext().getNext()); return tmp.getTrain(); } else {
private void split(Transaction tx, boolean isAddFirst) throws IOException { ListNode<Key, Value> extension = getContainingList().createNode(tx); if (isAddFirst) { // head keeps the first entry, insert extension with the rest extension.setEntries(entries.getHead().splitAfter()); extension.setNext(this.getNext()); extension.store(tx, isAddFirst); this.setNext(extension.getPageId()); } else { extension.setEntries(entries.getTail().getPrevious().splitAfter()); extension.setNext(this.getNext()); extension.store(tx, isAddFirst); getContainingList().setTailPageId(extension.getPageId()); this.setNext(extension.getPageId()); } store(tx, true); }
private void split(Transaction tx, boolean isAddFirst) throws IOException { ListNode<Key, Value> extension = getContainingList().createNode(tx); if (isAddFirst) { // head keeps the first entry, insert extension with the rest extension.setEntries(entries.getHead().splitAfter()); extension.setNext(this.getNext()); extension.store(tx, isAddFirst); this.setNext(extension.getPageId()); } else { extension.setEntries(entries.getTail().getPrevious().splitAfter()); extension.setNext(this.getNext()); extension.store(tx, isAddFirst); getContainingList().setTailPageId(extension.getPageId()); this.setNext(extension.getPageId()); } store(tx, true); }
private void split(Transaction tx, boolean isAddFirst) throws IOException { ListNode<Key, Value> extension = getContainingList().createNode(tx); if (isAddFirst) { // head keeps the first entry, insert extension with the rest extension.setEntries(entries.getHead().splitAfter()); extension.setNext(this.getNext()); extension.store(tx, isAddFirst); this.setNext(extension.getPageId()); } else { extension.setEntries(entries.getTail().getPrevious().splitAfter()); extension.setNext(this.getNext()); extension.store(tx, isAddFirst); getContainingList().setTailPageId(extension.getPageId()); this.setNext(extension.getPageId()); } store(tx, true); }
public void addToBack(String name, String telephoneNum, String email, String address, String dob) { //separate responsibilities, by constructing the node first addToBack(new ListNode(name,telephoneNum,email,address,dob)); } public void addToBack(ListNode newNode) { //do not use a continuation state in a class, fetch the head, inspect the head and if not null pass to the recursion method if(this.head == null) { this.head = newNode; } else { this.addToBack(this.head,newNode); } } public void addToBack(ListNode current, ListNode newNode) { //generic method that adds the node at the end if(current.getNext() == null) {//base case: current is the last node current.setNext(newNode); } else {//recursive case, current is not the next node addToBack(current.getNext(),newNode); } }