Declare linked list that will hold the elements in the stack

Assignment Help Data Structure & Algorithms
Reference no: EM131266003

Create a class called GenericStack that uses a linked list to implement a stack, which is a collection that lets you access entries on a first-in, last-out basis. Then you'll create another class that uses the GenericStack class.

The GenericStack class should implement these methods.

Push(element): Adds an element to the top of the stack.
Pop(): Returns and removes the element at the top of the stack
Peek():Returns but does not remove the element at the top of the stack.
Size(): Returns the number of entries in the stack.

A. Create a GenericStack class

i. Create a new class named GenericStack that specifies a type variable that provides for generics.

ii. Declare a linked list that will hold the elements in the stack. Then, use the linked list to implement the methods listed above.

B.. Create a class that uses GenericStack class

i. Open the GenericStackApp class. Then declare a generic stack at the beginning of the main method that will store-String objects.

ii. Add code to the main method that uses the push method to add at least 3 items to the stack. After each item is added, display its value at the console. Then use the size method to return the number of items in the stack and display that value

iii. Use the peek method to return the first item and display that item and use the size method to return the number of items again and display that value

iv.Use the pop method to return each item, displaying it as its returned and display the number of items one more time.

v. Output will be as follows:

Push: Apples
Push: Oranges
Push: Bananas

The stack contains 3 items

Peek: Bananas

The stack contains 3 items

Pop: Bananas
Pop: Oranges
Pop: Apples

The stack contains 0 items.

Reference no: EM131266003

Questions Cloud

How to calculate charges if user returns the book late : How to calculate charges if user returns the book late? How to determine the book condition/depreciation? Provision of scanning the barcode instead of entering the data manually.
Movement along the same demand curve for product : What happens to the demand curve and the supply curve when any of these determinants change? What would cause a change in demand versus a movement along the same demand curve for this product?
Uses weighted average with a periodic inventory system : During 2012, a company sells 300 units of inventory for $85 each. the company has the following inventory purchase transactions for 2012: DATE TRANSACTION NUMBER OF UNITS UNIT COST TOTAL COST jan. calculate ending inventory and cost of goods sold for..
Balance sheet for its investment in burke corporation : Gilman Company purchased 100,000 of the 250,000 shares of common stock of Burke Corporation on January 1, 2009, at $40 per share as a long-term investment. The records of Burke Corporation showed the following on December 31, 2009:  balance sheet for..
Declare linked list that will hold the elements in the stack : Create a new class named GenericStack that specifies a type variable that provides for generics. Declare a linked list that will hold the elements in the stack. Then, use the linked list to implement the methods listed above.
Discuss four components of corporate social responsibility : Discuss the four components of corporate social responsibility (CSR) and how they relate to a charitable campaign such as (Product) RED.
Decrease short-term interest rates : Suppose that the Federal Reserve is concerned about deflation in the future, so they decrease short-term interest rates. How will this affect long-term rates and the yield curve?
Appraisal value of this acquired land : On May 26, 2012, the Georgia Corp. acquired a piece of land by issuing 60,000 shares of its $9 par value common stock. The list price of the land was $625,000 and on May 26, 2012, Georgia's common stock was actively trading in the marketplace at $10 ..
Describe the effects of paralysis on the skeleton : 1. Following a severe spinal cord injury in the lumbar region, the voluntary muscles of the legs and hips will be paralyzed. Describe the effects of paralysis on theskeleton.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Setup an example rsa public/private key pair using primes

RSA with three primes would also work: n = pqr, ?(n) = (p?1)(q?1)(r?1), gcd(e, ?(n)) = 1, and d = e^?1 (mod ?(n)).

  What is the probability that you hire exactly n times

What is the smallest value of n such that an algorithm whose running time is 100n2 runs faster than an algorithm whose running time is 2n on the same machine?

  Using big-o notation state the runtime for this algorithm

1 consider searching algorithms on the following array of datanbsp22 21 9 4 16 2 10 14 20 31 26 19 17 28 8

  Neural and tree learning on continuous attributes

Compare and contrast the methods of learning these numbers in the two models.

  Relationships in a database model

Discuss different types of classifications and do they overlap, or do they each tell us something unique about the entity relationship?

  Greedy strategy for finding a shortest path

Think about the given greedy strategy for finding a shortest path from vertex start to vertex goal in a connected graph.

  Create a table that depicts the runtime for arrays of length

Create a table that depicts the runtime for arrays of length 1 to 10. Would you expect the general runtime to be O(n), O(n2), O(n3), or some other function of n? Explain.

  What other factors must managers address

The concept of opportunity cost and examination of how to calculate the cost of alternatives over single and multiple time periods

  Describe how to develop a subroutine

Describe how to develop a subroutine.

  What would ultimate result of algorithm

Single grain of wheat was to be placed on the first square of chess board, two on second, four on third, eight on the fourth, and so on, until all 64 squares had been filled. What would ultimate result of this algorithm have been?

  Various search trees and numerous sorting techniques

This week we were introduced to various search trees and numerous sorting techniques. Taking into consideration what you have learned this week, discuss how you can help Bob with his problem.

  How long would it take to fill the available storage space

How many cells can be in a computer's main memory if each cell's address can be represented by two hexadecimal digits? What if four hexadecimal digits are used? Explain your answer.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd