A stack is referred to as a last-in first-out

Assignment Help C/C++ Programming
Reference no: EM13500118

Overview & Requirements:

This lab, along with your TA, will help you navigate through designing, implementing, and testing a dynamic stack. Recall, a stack data structure is a restricted linked list, where only the top node in the stack may be accessed at any given time. A stack is referred to as a last-in, first-out (LIFO) structure as a result of this constraint. Furthermore, the operation of a stack must adhere to this restriction. A push ( ) operation adds a node to the top of the stack, a pop ( ) operation removes a node from the top of the stack, and a top ( ) or peek ( ) operation returns the data in the node at the top of the stack. We will visualize a stack in the following way:

Top ---> Item 3

              |

              Item 2

              |

             Item 1

              |

             NULL

Labs are held in a "closed" environment such that you may ask your TA questions. Please use your TAs knowledge to your advantage. You are required to move at the pace set forth by your TA. Please help other students in need when you are finished with a task. You may work in pairs if you wish. However, I encourage you to compose your own solution to each problem. Have a great time! Labs are a vital part to your education in CptS 122 so work diligently.

Tasks:

1.   For the following problem define a stackNode struct with data of type double. Implement the following operations for your stack data structure:

1.    isEmpty() - a predicate function which checks to see if the stack is empty; returns true if the stack is empty

2.    push() - inserts a node to the top of the stack; the node is allocated dynamically

3.    pop() - deletes a node from the top of the stack

4.    top() or peek() - returns the data in the node at the top of the stack

 

2.   Test your application. In the same project, create one more header file testStack.h and source file testStack.c (for a total of at least five files). The testStack.h file should contain function prototypes for test functions you will use on your stack functions. The testStack.c source file should contain the implementations for these test functions. You will have at least one test function per application function. For example, you will have an application function called pop() (or a function very similar) that is used to remove the top node from the stack. In this task, you will need to create a test function called testPop() that passes in various data directly into pop() to see if it works correctly.

3.   Tower of Hanoi: A very popular mathematical game or puzzle is referred to as the Tower of Hanoi. The idea behind the game is to find an efficient method for moving disks between three posts. Each disk has a different diameter, but all of them can be placed on the available posts. The goal of the game is to move all of the disks from one post to the another according the following rules:

1.    Only one disk may be transferred at a time

2.    Only the top disk on any post may be accessed at a give time

3.    No disk may be placed on top of a smaller disk at any point

At the start of the game, all of the disks must originally be placed such that the largest disk is on the bottom of the stack of one post, and the smallest is on the top of the stack on the same post. The disks should form a cone shape. Write a program to simulate the Tower of Hanoi game. For each move print the post number (1 - 3) from which the disk is taken, the diameter of the disk, and the resulting post on which the disk is placed. Also, show the current diameter of the disks on each post. You must use stacks to solve this problem! Initially start with three disks in your game. Note: if you visithttps://www.mazeworks.com/hanoi/, you will find an animation of how Tower of Hanoi should run.

4.   Maze: Generate a maze with a start to end path. The maze be represented by a two dimensional array of integers, where a wall may be represented by a 0 and a door may be represented by a 1. Find a path in your maze by using a stack. Modify your stackNode to store Point data for a path in a maze. APoint should be defined as a struct with row and column fields. Whenever a fork in the maze is encountered, store the coordinates of the fork on the stack. If the current path does not provide a path to the end of the maze, then the last forking point can be popped and a different path may be taken. This is called backtracking.

Reference no: EM13500118

Questions Cloud

What is rick filing status for 2012 : Rick, whose wife died in December 2011, filed a joint tax return for 2011. He did not remarry, but has continued to maintain his home in which his two dependent children live. What is Rick's filing status for 2012?
Adria lopez created success systems : Adria Lopez created Success Systems on October 1, 2013. The company has been successful, and Adria plans to expand her business. She believes that an additional $86,000 is needed and is investigating three funding sources.
Find its speed when it is farthest from the sun : A comet moves about the Sun in an elliptical orbit, with its closest approach to the Sun being about 0.680 AU and its greatest distance from the sun being 38.5 AU. what is its speed when it is farthest from the Sun
List the name of the fund : 1. (TCOs D, E, F, and G) Please list the name of the fund(s) in which each of the following transactions or events would be recorded.
A stack is referred to as a last-in first-out : This lab, along with your TA, will help you navigate through designing, implementing, and testing a dynamic stack. Recall, a stack data structure is a restricted linked list, where only the top node in the stack may be accessed at any given time
What is the new spacing between bright fringes : A Young's double-slit interference experiment gives bright fringes separated by 30.5 cm on a screen when the experiment is performed in air. What is the new spacing between bright fringes
Uses the macrs statutory percentage method : 1) Olga is the proprietor of a small business. In 2014, the business's income, before consideration of any cost recovery or § 179 deduction, is $104,000.
Obtain the momentum of the electron : A 0.534-nm photon collides with a stationary electron. After the collision, the electron moves forward and the photon recoils backwards. Find the momentum of the electron
Prepare and describe each incorrect assumption : Prepare and describe each incorrect assumption, statement and/are inappropriate application in the above procedures

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Use a loop in main to efficiently handle all three persons

Plan and finish writing the main program, and all the functions, including a constructor. Use a loop in main to efficiently handle all three persons' data.

  Prepare a program to print the permutation

write a program to print the permutation that lexicographically precedes the given input permutation. If the given permutation is the lexicographically least permutation, then print the input permutation itself.

  The fibonacci sequence

In the novel "The DaVinci Code", a scrambled version 13, 3, 2, 21, 1, 1, 8, 5 of the first eight Fibonacci numbers appear as one of the clues left by murdered museum curator Jacques Sauniere. In this assignment, we will do something related to t..

  Write a program that stimulates a bouncing ball

Write a program that stimulates a bouncing ball by computing its height in feet at each second as time passes on a simulated clock. At time zero, the ball begins at height zero.

  Which of the following is a true statement

Which of the following is a true statement?

  Cashregister class that can be used with the retailitem clas

Write a CashRegister class that can be used with the RetailItem class that you wrote in Part 1. The CashRegister class should simulate the sale of a retail item. It should have a constructor that accepts a RetailItem object as an argument.

  Program to compute surface area of sphere using function

Write down a program in C++ to compute surface area of sphere using a function. As sample run, write down the surface areas of spheres with radii.

  Write in c++. read an inputfile.txt

write in C++.  read an inputFile.txt which contains integers that are virutal addresses, and I am suppossed to translate that into physical addresses using a page table and a transition lookaside buffer

  Create a graphical calculator with buttons

Create a graphical calculator with buttons that can add, subtract, multiply, divide, +/-, Sin, Cos, Tan, clear and Modulus and write a method for each of these calculations that will accept the needed incoming numbers and return the calculated value.

  Write a c program that asks for and reads in two integers

Write a C program that asks for and reads in two integers and then reports if one is a multiple of the other.

  Why does the neverwet spray protect it from water

As is know, acetone is a polar molecule like water, so isn't it suppose to mix? So my question is: why does the Neverwet spray protect it from water but not from oils and detergents?

  Write a program which accepts the total of food and drink

Write a program which accepts the total of food and drink purchased for a restaurant bill as input. The output should be adjusted bill with a sales tax of six percent 6% and a tip (gratuity) of 15%.

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