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 :
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;
}
}
}
}
Get Answers For Free
Most questions answered within 1 hours.