Lab 02, Data Abstractions and Structures, CSE 274, Fall 辅导、辅导java程序、辅导java linked list编程

- 首页 >> Java编程


Lab 02, Data Abstractions and Structures, CSE 274, Fall 2018

Linked List

Inthis lab,wewillimplementtheLinkedList. The list will contain a sequence of strings. First, we

will design the Node class (Node.java). It will contain an integer data and a reference to the next

Node. The constructor of Node class receives an integer and assigns it to the data field.It also has a

default constructor.

Then we will design another class named LinkedList (LinkedList.java). LinkedList class has an

instance variable called firstNode of type Node. It has the following methods:

1. public LinkedList()

Thedefault constructor of class LinkedList.

2. int getCurrentSize()

Gets the current number of entries in this list.

3. public T[] toArray()

Retrieves all entries that are in this bag.

4. public void addToHead(String newEntry)

Adds the specified new entry to the start of the linked list.

5. public void addToTail(StringnewEntry)

Adds the specified new entry to the end of the linked list.

6. public Node removeHead()

Removes and returns the first item from the list. If the list has no nodes, returns null.

7. public Node removeTail()

Removes and returns the last item from the list.

Implement allthe methods inLinkedList class. Wewill work together to complete Node class and

first methods from LinkedList class. You have to complete the rest by yourself.

Grading Rubric:

Each method is worth 10 points. Total 100 points.

LinkedList() 5

getCurrentSize() 5

toArray() 20

addToHead(String newEntry) 10

addToTailHead(String newEntry) 20

removeHead() 10

removeTail() 30

Data Next Node

Before getting started:

● Create a new project namedLab3LinkedList

● Nowdownload theLinkedListTester class andadditto yourproject.Runandtest your

code.

You will have the following output:

========================================

Adding A to the Head of the bag:

The bag contains 1 string(s), as follows:

A

========================================

Adding B to the Head of the bag:

The bag contains 2 string(s), as follows:

B A

========================================

Adding C to the Tail of the bag:

The bag contains 3 string(s), as follows:

B A C

========================================

Adding D to the Tail of the bag:

The bag contains 4 string(s), as follows:

B A C D

========================================

Removing an entry from the head:

The bag contains 3 string(s), as follows:

A C D

========================================

Removing an entry from the Tail:

The bag contains 2 string(s), as follows:

A C

What to do when you are done:

● Submitjavafiles(Node.java,LinkedList.java)totheappropriatesubmissionfolderon

Canvas.


站长地图