[Solved] COMP1400 Lab10- Working with global and local variables

$25

File Name: COMP1400_Lab10-_Working_with_global_and_local_variables.zip
File Size: 518.1 KB

SKU: [Solved] COMP1400 Lab10- Working with global and local variables Category: Tag:
5/5 - (1 vote)

Stack Implementation: A stack, like an array, can store multiple data items of the same type. However, the operations on a stack are limited: we can either push an item onto the stack (add it to one endthe stack top) or pop it from the stack (remove it from the same end). Examining or modifying an item thats not at the top of the contents is forbidden.

One way to implement a stack in C is to store its items in an array, which well call contents. A separate integer variable named top marks the position of the stack top. To push an item on the stack, we simply store the item in contents at the position indicated by top, then increment top. Popping an item requires decrementing top, then using it as an index into contents to fetch the item thats being popped*.

Based on this outline, the attached globalContents.c is a program that declares the contents and top variables for a stack and provides a set of functions that represent operations on the stack. All four functions need access to the top variable, and two functions need access to contents, so contents and top are declared globally.

Modify the globalContents.c program by moving the contents array and top into main (declare local variables), which will pass them as arguments to push, pop,

isEmpty and isFull functions as follows:

  • int isEmpty(int top);
  • int isFull(int top);
  • int pop(int contents[], int top); int push(int data , int contents[], int top);

Save the program in a file named as localContents.c, in the working directory on the PC you are using and demonstrate it to GA/TAs.

Hint: The value of top should be updated in the main function.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] COMP1400 Lab10- Working with global and local variables
$25