SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

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

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 2 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 22 Dec 2017 My Price 10.00

driven program that implements the following doubly

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;
      }
    }
  }
 
  public static void main(String a[]){
   
   
  }
}

Answers

(5)
Status NEW Posted 22 Dec 2017 10:12 AM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)