ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 12 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 25 Apr 2017 My Price 9.00

Write a menu driven program

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 :

 

  • INSERT (at the beginning)
  • INSERT_ALPHA (in alphabetical order)
  • DELETE (Identify by contents, i.e. "John", not #3)
  • COUNT
  • CLEAR

 

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;

Answers

(11)
Status NEW Posted 25 Apr 2017 06:04 AM My Price 9.00

-----------

Not Rated(0)