Data Structures question- JAVA

User Generated

ChcclOnex

Programming

De Anza College

Description

In this lab you will explore two implementations of the ADT list. The first implementation will use an array and the second will use a linked structure. In both cases you will create new methods that work directly with the implementations. You will implement a reverse method that will reverse the order of the items in the list. You will also implement a cycle method that will move the first item in the list to the last position. The java files are attached as word documents since I cannot attach a .java file.

Unformatted Attachment Preview

import java.io.*; /** A linked implementation of the ADT List. * * This code is from Chapter 14 of * Data Structures and Abstractions with Java 4/e * @author Frank M. Carrano * * Modifications were made by Charles Hoot: * The toString method is overwritten to give a nice display of the items in * the list in this format { } * * An alternate display method has been created to print the list one item * to a line along with the index * * Stubs were added for the methods needed to complete Lab 13 * * @version 4.0 */ class LList implements ListInterface { private Node firstNode; // Reference to first node of chain private int numberOfEntries; public LList() { initializeDataFields(); } // end default constructor public void clear() { initializeDataFields(); } // end clear // Initialize the class's data fields to indicate an empty list. private void initializeDataFields() { firstNode = null; numberOfEntries = 0; } public void add(T newEntry) { Node newNode = new Node(newEntry); if (isEmpty()) { firstNode = newNode; } else // Add to end of nonempty list { Node lastNode = getNodeAt(numberOfEntries); lastNode.setNextNode(newNode); // Make last node reference new node } // end if numberOfEntries++; } // end add public void add(int newPosition, T newEntry) { if ((newPosition >= 1) && (newPosition 1 Node nodeBefore = getNodeAt(newPosition - 1); Node nodeAfter = nodeBefore.getNextNode(); newNode.setNextNode(nodeAfter); nodeBefore.setNextNode(newNode); } // end if numberOfEntries++; } else { throw new IndexOutOfBoundsException("Illegal position given to add operation."); } } // end add public T remove(int givenPosition) { T result = null; // Teturn value if ((givenPosition >= 1) && (givenPosition = 1) && (givenPosition = 1) && (givenPosition
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Here i...


Anonymous
I use Studypool every time I need help studying, and it never disappoints.

Studypool
4.7
Indeed
4.5
Sitejabber
4.4

Related Tags