Question

In: Computer Science

follow pseudo 1) Create class called Node Declare private integer called data (or any other name)...


follow pseudo

1)
Create class called Node

Declare private integer called data (or any other name)
Declare private Node called link (or any other name)

2) Declare constructor
Should be public (ex: Node)
where:
link is equal to null
data is equal to zero

3) Declare another constructor
public Node with parameters integer d, Node n
where:
data is equal to d
link is equal to n

4)
Declare function to set link to next Node
link equal to n

5)

Declare function to set data to current Node
public void setData with parameter integer d
where
data equal to d
  
6)
Declare function to get data from current Node
public integer getData
return data

7)
Create class called linkedlist (or any other name)
  
declare private Node start
declare private Node end
declare public integer size
  
inside of that class declare constructor;
start equal to null
end equal to null
size equal to zero
  
8)
Declare function to check if list is empty
should be public boolean any name (empty or something else)
return start equal to null
  
9)
Declare function to get size of list
should be public integer getSize
return size
  
10)

Declare function to insert an element at beginning
declare public void insert at start (some name indicating to insert in the beginning) with parameter integer value
  
Declare:
Node (object name ex: as) equal to new Node (value, null)
increment size
  
if condition start equal to null
  
start equal to as
end equal to start
  
else condition
  
as.setLink (start)
start equal to as
  
  
11)
Declare function to insert an element at end

Should be public void insert at end (or something) with parameter integer value
Declare:
Node (object name ex: as) equal to new Node (value, null)
increment size
if condition start equal to null
  
start equal to as
end equal to start
  
else condition
  
as.setLink (as)
end equal to as
  
12)

Declare function to insert an element at position
Should be public void insert in position (or something similar) with paramaters integer value and integer position

Declare:
Node (object name ex: as) equal to new Node (value, null)

Node (called: es) equal to start

Position equal to position minus 1

create for loop where i equal 1 and i less then size and increment i

inside of that loop create condition
if i equal position

Node temp equal to es.getLink();

es.setLink(as)
as.setLink(temp)
break

//after closed bracket continue

es equal to es.getLink();
  
//after closed bracket
  
increment size
  
  
13)

Declare function to delete an element at position

Should be public void delete in position (or something similar) with parameter integer position

condition if position equal to 1

start = start.getLink();

decrement size

return

condition if position equal to size

Node a (or any other name) equal to start

Node b (or any other name) equal to start

loop while a not equal to end

b equal to a

a equal to a.getLink();

//after closed bracket continue

end equal to b

end.setLink(null)

decrement size

return

//after closed bracket continue

Node aa(or any other name) equal to start

position equal to position minus 1

create for loop where i equal 1 and i less size minus 1 and increment i

condition if i equal to position

Node temp(or any name you want) equal to aa.getLink();

temp equal to temp.getLink();

aa.setLink(temp);

break

//after closed bracket continue

aa equal aa.getLink();

//after another closed bracket

decrement size


14)


Declare function to display
Should be public void display
sys.print Linked list:
condition if size equal to zero
  
sys.print empty value
return
  
condition if start.getLink() equal to null
sys print(start.getData());
return
  
Node aaa equal to start
sys.print(start.getData() + " - ");
  
aaa equal to aaa.getLink();
  
//after closed bracket
sys.print (aaa.getData() + " \n");
  
  
  
  
15)
  
  
Scanner scan = new Scanner(System.in);

  

linkedList list = new linkedList();

System.out.println("Linked List: ");

char ch;

  
do

{

System.out.println("\nLinked List Menu\n");

System.out.println("1. Insert at start");

System.out.println("2. Insert at end");

System.out.println("3. Insert in Position");

System.out.println("4. Delete in Position");

System.out.println("5. Check if its empty") ;

System.out.println("6. Get Size of Linked List");

int choice = scan.nextInt();

switch (choice)

{

case 1 :

...............
........................
.................................
..........................................













Solutions

Expert Solution

#Completing pseudo code

1)

Create class called Node
Declare private integer called data (or any other name)
Declare private Node called link (or any other name)

2)

Declare constructor
Should be public (ex: Node)
where:
link is equal to null
data is equal to zero

3)

Declare another constructor
public Node with parameters integer d, Node n
where:
data is equal to d
link is equal to n

4)
Declare function to set link to next Node
link equal to n

5)

Declare function to set data to current Node
public void setData with parameter integer d
where
data equal to d
  
6)
Declare function to get data from current Node
public integer getData
return data

7)
Create class called linkedlist (or any other name)
declare private Node start
declare private Node end
declare public integer size
  
inside of that class declare constructor;
start equal to null
end equal to null
size equal to zero
  
8)
Declare function to check if list is empty
should be public boolean any name (empty or something else)
return start equal to null
  
9)
Declare function to get size of list
should be public integer getSize
return size
  
10)

Declare function to insert an element at beginning
declare public void insert at start (some name indicating to insert in the beginning) with parameter integer value
  
Declare:
Node (object name ex: as) equal to new Node (value, null)
increment size
  
if condition start equal to null
  
start equal to as
end equal to start
  
else condition
  
as.setLink (start)
start equal to as
  
  
11)
Declare function to insert an element at end

Should be public void insert at end (or something) with parameter integer value
Declare:
Node (object name ex: as) equal to new Node (value, null)
increment size
if condition start equal to null
  
start equal to as
end equal to start
  
else condition
  
as.setLink (as)
end equal to as
  
12)

Declare function to insert an element at position
Should be public void insert in position (or something similar) with paramaters integer value and integer position

Declare:
Node (object name ex: as) equal to new Node (value, null)

Node (called: es) equal to start

Position equal to position minus 1

create for loop where i equal 1 and i less then size and increment i

inside of that loop create condition
if i equal position

Node temp equal to es.getLink();

es.setLink(as)
as.setLink(temp)
break

//after closed bracket continue

es equal to es.getLink();
  
//after closed bracket
  
increment size
  
  
13)

Declare function to delete an element at position

Should be public void delete in position (or something similar) with parameter integer position

condition if position equal to 1

start = start.getLink();

decrement size

return

condition if position equal to size

Node a (or any other name) equal to start

Node b (or any other name) equal to start

loop while a not equal to end

b equal to a

a equal to a.getLink();

//after closed bracket continue

end equal to b

end.setLink(null)

decrement size

return

//after closed bracket continue

Node aa(or any other name) equal to start

position equal to position minus 1

create for loop where i equal 1 and i less size minus 1 and increment i

condition if i equal to position

Node temp(or any name you want) equal to aa.getLink();

temp equal to temp.getLink();

aa.setLink(temp);

break

//after closed bracket continue

aa equal aa.getLink();

//after another closed bracket

decrement size


14)


Declare function to display
Should be public void display
sys.print Linked list:
condition if size equal to zero
  
sys.print empty value
return
  
condition if start.getLink() equal to null
sys print(start.getData());
return
  
Node aaa equal to start
sys.print(start.getData() + " - ");
  
aaa equal to aaa.getLink();
  
//after closed bracket
sys.print (aaa.getData() + " \n");
  
  
  
  
15)
  
Scanner scan = new Scanner(System.in);

linkedList list = new linkedList();

System.out.println("Linked List: ");

char ch;  
do

{

tag1:

System.out.println("\nLinked List Menu\n");

System.out.println("1. Insert at start");

System.out.println("2. Insert at end");

System.out.println("3. Insert in Position");

System.out.println("4. Delete in Position");

System.out.println("5. Check if its empty") ;

System.out.println("6. Get Size of Linked List");

int choice = scan.nextInt();

switch (choice)

{

case 1 : Insert an element to be stored at the beginning of linkedlist
int num=scan.nextInt();

Call the method insert_at_start and pass num as an input to be stored at the beginning.
i.e call insert_at_start(the value taken input i.e. num)

Break from the switch statement once the above statement executed using break command.


case 2 : Insert an element to be stored at the end of linkedlist
int num=scan.nextInt();

Call the method insert_at_end and pass num as an input to be stored at the end.
i.e call insert_at_end(the value taken input i.e. num)

Break from the switch statement once the above statement executed using break command.

case 3 : Insert an element to be stored at specific position in linkedlist
int num=scan.nextInt();

Call the method insert_in_position and pass num as an input to be stored at the beginning.
i.e call insert_in_position(the value taken input i.e. num)

Break from the switch statement once the above statement executed using break command.

case 4 : Input an element to be deleted from a specific position in linkedlist.
int num=scan.nextInt();

Call the method delete_in_position and pass num as an input to be stored at the beginning.
i.e call delete_in_position(the value taken input i.e. num)

Break from the switch statement once the above statement executed using break command.


case 5: Call the function empty which has a return type of boolean to check whether its empty
or not i.e. call empty and store its return bool value in a variable of type bool.

Print if linked list is empty or not( check the returned bool for 0 or 1)

Break from the switch statement once the above statement executed using break command.


case 6: Call the function getSize which has a return type of integer to get the size of linkedlist
i.e. call getSize and store return value in a variable.
  
Print the return value i.e. the current size of the linkedlist.

Break from the switch statement once the above statement executed using break command.

default: Print the default error message to give correct input from 1 to 6 only.


Close the do-while loop with the condition to check if user want to enter more or quit the interactive mode i.e

Run while loop and ask user to confirm more inputs or not(can be done by taking input as Y or N)

if yes, go to tag1, otherwise exit.



Related Solutions

please follow this pseudocode 1) Create class (any name you want)ex: aS 2) Declaring private integer...
please follow this pseudocode 1) Create class (any name you want)ex: aS 2) Declaring private integer array empty one ex: name arr[] 3) Declare private integer variables top, size and len (my example) 4) Declare constructor for the class with the same name and inside of that public aS declare (parameter ex: int n)    5) Inside of that constructor method write command where: size is equal to n len is equal to zero array (name) is equal to new...
write the code based on this pseudocode //Create Class any name (ex: aQ) //Declaring private integer...
write the code based on this pseudocode //Create Class any name (ex: aQ) //Declaring private integer array empty one ex: name arrQ[] //Declare private integers front, rear, size and len (example, but you call any other names) //Write constructors Called public and same name of the class (parameters integer n) Inside Declare where: size is equal to n len is equal to zero arrQ is equal to new integer[size] front is equal minus 1 rear is equal minus 1 //Declare...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
Write a class called Person that has two private data members - the person's name and...
Write a class called Person that has two private data members - the person's name and age. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Write a separate function (not part of the Person class) called std_dev that takes as a parameter a list of Person objects and returns the standard deviation of all their ages (the population standard deviation that uses a denominator...
Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter,...
Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter, and pi is declared as double. Create the following for the Circle object: ● Implicit constructor (default constructor) ● Void method Calculate (double pi, int radius) to calculate the area of the Circle object. The method must include a system.out statement that displays the area value. Use the following formula to calculate area of the circle: Area = pi * (r * r) Your...
myLinkedList.java>>>>>>>> public class MyLinkedList implements MiniList<Integer>{ /* Private member variables that you need to declare: **...
myLinkedList.java>>>>>>>> public class MyLinkedList implements MiniList<Integer>{ /* Private member variables that you need to declare: ** The head pointer ** The tail pointer */ public class Node { // declare member variables (data and next) // finish these constructors public Node(int data, Node next) {} public Node(int data) {} // HINT: use this() with next = null } // Initialize the linked list (set head and tail pointers) public MyLinkedList() {} @Override public boolean add(Integer item) { return false; }...
Exercise #1: Create an abstract class called GameTester. The GameTester class includes a name for the...
Exercise #1: Create an abstract class called GameTester. The GameTester class includes a name for the game tester and a boolean value representing the status (full-time, part-time). Include an abstract method to determine the salary, with full-time game testers getting a base salary of $3000 and part-time game testers getting $20 per hour. Create two subclasses called FullTimeGameTester, PartTimeGameTester. Create a console application that demonstrates how to create objects of both subclasses. Allow the user to choose game tester type...
# List the two private member variables (including name and functionality) in the node class. #Write...
# List the two private member variables (including name and functionality) in the node class. #Write a general pattern for a loop statement that traverses all the nodes of a linked list
IN JAVA PLEASE Create a class called Child with an instance data values: name and age....
IN JAVA PLEASE Create a class called Child with an instance data values: name and age. a. Define a constructor to accept and initialize instance data b. include setter and getter methods for instance data c. include a toString method that returns a one line description of the child
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT