Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the implementation of LinkedQueue class presented in this chapter. Specifically, complete the implementations of the first, isEmpty, size, and toString Methods. /* * To

Complete the implementation of LinkedQueue class presented in this chapter. Specifically, complete the implementations of the first, isEmpty, size, and toString Methods.

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package jsjf;

import jsjf.exceptions.*; import java.util.Iterator;

/** * Represents a linked implementation of a stack. * * @author Lewis and Chase * @version 4.0 */ public class LinkedStack implements StackADT { private int count; private LinearNode top;

/** * Creates an empty stack. */ public LinkedStack() { count = 0; top = null; }

/** * Adds the specified element to the top of this stack. * @param element element to be pushed on stack */ public void push(T element) { LinearNode temp = new LinearNode(element);

temp.setNext(top); top = temp; count++; }

/** * Removes the element at the top of this stack and returns a * reference to it. * @return element from top of stack * @throws EmptyCollectionException if the stack is empty */ public T pop() throws EmptyCollectionException { if (isEmpty()) throw new EmptyCollectionException("stack");

T result = top.getElement(); top = top.getNext(); count--; return result; } /** * Returns a reference to the element at the top of this stack. * The element is not removed from the stack. * @return element on top of stack * @throws EmptyCollectionException if the stack is empty */ public T peek() throws EmptyCollectionException { // To be completed as a Programming Project }

/** * Returns true if this stack is empty and false otherwise. * @return true if stack is empty */ public boolean isEmpty() { // To be completed as a Programming Project } /** * Returns the number of elements in this stack. * @return number of elements in the stack */ public int size() { // To be completed as a Programming Project }

/** * Returns a string representation of this stack. * @return string representation of the stack */ public String toString() { // To be completed as a Programming Project } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions