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

  Find cost of sorting the relation

Suppose the cost of seek is 5milliseconds, while the disk transfer rate is 40 mgbytes per second. Find the cost of sorting the relation , in seconds, w/bb = 1 & w/ bb= 100.

  Create an assignment on powerpoint presentation

consists of  (4) sections:- a written project plan, revised business requirements document, project plan PowerPoint presentation, and a finalized project plan.

  Explain spacewise efficient implementation two-stack data

Structure of such two-stack data type would consist of two arrays and two top pointers. Describe why this may not be a spacewise efficient implementation.

  What are the characteristics of a good algorithm

What is an algorithm? What are the characteristics of a good algorithm and what do you mean by complexity of an algorithm? Explain the meaning of worst case analysis and best case analysis with an example.

  Show how the following values would be stored by machines

Show how the following values would be stored by machines with 32-bit words, using little endian and big endian format. Assume each value starts at address 016. Draw a diagram of memory for each, placing the appropriate values in the correct (and ..

  Write program to do operaretions of stack-push-pop-peek

Write down the program which does the basic stack operations: Make the stack. Push element into the stack. Pop element from the stack.

  What are the different types of query optimization algorithm

Describe three data fragmentation strategies. Give some examples of each.

  Creating an access database

PLUS is a corporation that makes all types of visual aids for judicial proceedings. Customers are usually private law firms, although the District Attorney's office has occasionally contracted for its services.

  Find an optimal hamilton circuit stating at vertex c

find an optimal Hamilton Circuit stating at Vertex C

  Prove dijkstras token ring reaches legitimate con­figuration

Prove that Dijkstra's token ring reaches a legitimate con­figuration in O(N2) steps. Shorten the analysis by giving a single norm function, quadratically bounded in N, that decreases with every step of the algorithm.

  Implement a nice graph datastructure

Implement a nice graph datastructure. Implement two different greedy graph coloring algorithms. Shortest path algorithm and MST algorithms.

  Generalize 2-3 algorithms for insert and delete

Generalize the 2-3 algorithms for INSERT and DELETE to K-J trees, where non-leaf vertices have between K and J children for fixed integers K >=2, and J>= 2K-1.

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