Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 12 Weeks Ago, 3 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Need some help on an assignment. Below is the question to the assignment and attached is what I have so far. Could I get it to making it more efficient? Also I am getting an error with my current code. Could you input some light notes in the revised version so I could follow along? Thank you
Â
Write a menu driven program that implements the following doubly linked list operations :
Â
Â
import java.util.*;public class DoublyLinkedList {private Node head;private Node tail;public DoublyLinkedList() {head=null;tail=null;}private class Node {String element;Node next;Node prev;public Node(String s) {element = s;next = null;prev = null;}}public int count() {Node cur=head;int c=0;while(cur!=null){c++;cur=cur.next;}return c;}public void addFirst(String element) {Node tmp = new Node(element);if(head != null ) {tmp.next=head;head.prev = tmp;}head = tmp;if(tail == null) {tail = tmp;}}public void clear(){head=null;tail=null;}public void insert_alpha(String element){Node cur=head;if(cur==null){if(cur.element.compare(element) > 0){Node tmp = new Node(element);tmp.next=cur;tmp.prev=cur.prev;cur.prev.next=tmp;cur.prev=tmp;}else{cur=cur.next;