Question

JAVA *** All data structures, including array operations, queues, stacks, linked lists, trees, etc need to...

JAVA

*** All data structures, including array operations, queues, stacks, linked lists, trees, etc need to be implemented by 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

Homework Answers

Answer #1

Raw_code:

import java.io.*;
class Driven{
   String names[] = new String[20];
   void Insert( String name){
       names[0] = name;
       for (int i = 1; i<names.length; i+=1){
               names[i] = names[i-1];
       }
   }
   void Insert_ALPHA(String name){
       for ( int j = 0; j<names.length; j++){
           for ( int i = j+1; i<names.length; i++){
               if (names[i].compareTo(names[j])<0){
                   String t = names[j];
                   names[j] = names[i];
                   names[i] = t;
               }
           }
       }
       for ( int i = 0; i<names.length-1; i+=1){
           if (names[i].compareTo(name)>0){
               String temp = names[i];
               names[i+1] = temp;
           }
       }
   }
   void Delete(String name){
       for ( int k = 0; k<names.length-1; k+=1){
           if (names[k].compareTo(name)==0){
               String temp = names[k+1];
               names[k] = temp;
           }
       }
   }
   void Count( String name){
       int count = 0;
       for ( int k = 0; k<names.length; k+=1){
           if (names[k].compareTo(name)==0){
               count+=1;
           }
       }
       System.out.println("Count = " + count);
   }
   void Clear(){
       for ( int k = 0; k<names.length; k+=1){
           System.out.println(names[k]);
           names[k] = "";
       }
   }
}
public class hello{
   public static void main(String args[])
   throws IOException{
       BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
       char k;
       System.out.println("Enter 1 to Insert name.");
       System.out.println("Enter 2 to Insert in alphabetic order.");
       System.out.println("Enter 3 to Delete name.");
       System.out.println("Enter 4 to Count.");
       System.out.println("Enter 5 to Clear.");
       k = (char)br.read();
       Driven d = new Driven();
       String name = new String();
       name = br.readLine();
       switch(k){
           case ('1'): {
               name = br.readLine();
               d.Insert(name);
               break;
           }
           case('2'):{
               name = br.readLine();
               d.Insert_ALPHA(name);
               break;
           }
           case('3'):{
               name = br.readLine();
               d.Delete(name);
               break;
           }
           case('4'):{
               name = br.readLine();
               d.Count(name);
               System.out.println(name);
               break;
           }
           case('5'):{
               d.Clear();
               break;
           }
       }
   }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
This is in java and you are not allowed to use Java API classes for queues,...
This is in java and you are not allowed to use Java API classes for queues, stacks, arrays, arraylists and linkedlists. You have to write your own implementations for them. You should construct a BST by inserting node values starting with a null tree. You can re-use the code for the insert method given in the sample code from the textbook. -insert method is provided below Your code should have a menu driven user interface at the command line with...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(),...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(), and isEmpty(). For this assignment, enqueue() will be implemented in an unusual manner. That is, in the version of enqueue() we will use, if the element being processed is already in the queue then the element will not be enqueued and the equivalent element already in the queue will be placed at the end of the queue. Additionally, you must implement a circular queue....
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs in Chapter 1 of your textbook are not complete. They are used for illustration purpose only. The implementation of Listing 1-1 on page 39 is explained in Chapter 2. And, in order to see the result of using it, we will need the following set of files: i. BagInteface.java – the specification only. ii. ArrayBag.java – the implementation of BagInerface.java. iii. ArrayBagDemo.java – a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT