Sunday, August 2, 2009

Pusha and Pop arrays. Need crtique on stuff I have. C programming?

Write a program that implements a stack with at most 30 integer elements with operations push and pop as defined


below:


A. Declare an integer array with a size of 30 elements.


B. Write a function called push that will insert an integer into the array.


C. Write a function called pop that removes the top-most element in the array.


D. Write a main function that takes input from the user based on integers: 1 - PUSH; 2 - POP; 3 - EXIT. Whenever


the user enters 1 (for PUSH), the integer that follows it is the element to be pushed.


E. The program prints as output the elements of the stack at the end of input and prints the maximum size to


which the stack grew during the operation.





#define value 30


void push(int value)


{


stack[i]=value;


i++;


}


int pop()


{


int temp=stack[i];


stack[i]=0;


i--;


return temp;


}

Pusha and Pop arrays. Need crtique on stuff I have. C programming?
when i=0, u need to give a print statement " underflow "
Reply:What happens when i = 0 and you pop?


No comments:

Post a Comment