answersLogoWhite

0

class Node

{

public Node next;

public Node previous;

public int item;

public Node(int item)

{

this.item = item;

}

public Node(int item, Node previous)

{

this.item = item;

this.previous = previous;

}

}

public class DoublyLinkList {

public static void main(String[] args) {

// TODO Auto-generated method stub

DoublyLinkList doublyLinkList = new DoublyLinkList();

Node head = doublyLinkList.addNodeFIFO(null, 1);

head = doublyLinkList.addNodeFIFO(head, 2);

head = doublyLinkList.addNodeFIFO(head, 3);

head = doublyLinkList.addNodeFIFO(head, 4);

head = doublyLinkList.addNodeFIFO(head, 5);

doublyLinkList.printdoublyLinkList(head);

Node current = head;

current = doublyLinkList.movePrevious(current);

current = doublyLinkList.moveNext(current);

current = doublyLinkList.movePrevious(current);

current = doublyLinkList.moveNext(current);

current = doublyLinkList.moveNext(current);

current = doublyLinkList.moveNext(current);

current = doublyLinkList.moveNext(current);

current = doublyLinkList.moveNext(current);

current = doublyLinkList.moveNext(current);

current = doublyLinkList.moveFirst(current);

current = doublyLinkList.moveLast(current);

// head = doublyLinkList.deleteNodeFIFO(head, 3);

//

// doublyLinkList.printdoublyLinkList(head);

//

// head = doublyLinkList.deleteNodeFIFO(head, 1);

//

// doublyLinkList.printdoublyLinkList(head);

//

// head = doublyLinkList.deleteNodeFIFO(head, 5);

//

// doublyLinkList.printdoublyLinkList(head);

}

public Node addNodeFIFO(Node head, int item)

{

System.out.println("In Add Node");

if(head item)

{

cNode.next = nNode.next;

break;

}

else

{

cNode = nNode;

nNode = nNode.next;

}

}

return head;

}

public void printdoublyLinkList(Node head)

{

while(head != null)

{

System.out.println(head.item);

head = head.next;

}

}

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

How can implement round robin sceduler in java using circular doubly linked list?

I'm sorry brother


How do you write a Java program to implement weighted queue using circular doubly linked list?

Add weights to the elements of the queue and use an algorithm to sort the queue every time an element is added.


What is mean linked list in java?

A LinkedList is an implementation of the List interface. It is a collection that is ordered by index position, and the elements are doubly-linked to one another. The linking allows for addition and removal of elements from beginning or end. This class, as of Java 5, also implements the java.util.Queue interface.


How do you import others codes in java?

using servlets, php, and database we can connect import codes into java


Circular linked list in java Sample?

Basically, A linked list that has its tail linked to its head, usually the tail is kept track of since it provides constant access to both the end and the front of the linked list. ListNode x = new ListNode( value, null); //a ListNode with no next x.setNext( new ListNode( value, null)); // make its next another ListNode with no next x.getNext().setNext(x); // set the new node's next to my old node, now you have a circular linked list.


How can I implement a merge sort algorithm for a doubly linked list in Java?

To implement a merge sort algorithm for a doubly linked list in Java, you can follow these steps: Divide the doubly linked list into two halves. Recursively sort each half using merge sort. Merge the two sorted halves back together in sorted order. You can achieve this by creating a mergeSort() method that takes the doubly linked list as input and recursively divides and merges the list. Make sure to handle the merging process for doubly linked lists by adjusting the pointers accordingly. Here is a basic outline of how you can implement this algorithm in Java: java public class MergeSortDoublyLinkedList public Node mergeSort(Node head) if (head null head.next null) return head; Node middle getMiddle(head); Node nextOfMiddle middle.next; middle.next null; Node left mergeSort(head); Node right mergeSort(nextOfMiddle); return merge(left, right); private Node merge(Node left, Node right) if (left null) return right; if (right null) return left; Node result null; if (left.data right.data) result left; result.next merge(left.next, right); result.next.prev result; else result right; result.next merge(left, right.next); result.next.prev result; return result; private Node getMiddle(Node head) if (head null) return head; Node slow head; Node fast head; while (fast.next ! null fast.next.next ! null) slow slow.next; fast fast.next.next; return slow; class Node int data; Node prev; Node next; public Node(int data) this.data data; This code snippet provides a basic implementation of the merge sort algorithm for a doubly linked list in Java. You can further customize and optimize it based on your specific requirements.


What are the basic types of link list in java?

linear circular double linked linear double linked circular Knowing the names does not help much when your teacher will require you to actually know what the names mean. Start reading. Programming requires lots of reading.


What are good Java script codes?

depending on the intention of the javascript codes you wish to write. there is much you can do with javascript but the only way to find out what "good Java script codes" are is to explore what you want the Javascript to do on the page.


Codes in making a receipt using a java?

yes


Which programming language generates byte codes?

Java


Is java is a platform independent language?

Yes. Apart from lower grade mobiles which have no support for java, java written codes can execute on all platforms and all devices.


Is there somebody help me to find a sites or source codes that will count the running time complexity of a certain codes in Java?

Google