S
Sandie C
Hi All
newbie here
i am trying to push integers to a stack and when the input is complete, I
would like to pop them and print them out as they come off the stack.
TIA
Sandie
code here
#include <stdio.h>
#define MAXSTACK 1000
int push(int );
int pop (int );
int stack[MAXSTACK]; /* define stack size*/
int count; /* count for checking if stack full, data for the data to move
around the stack*/
void main(void){
int data;
printf("please input Data type (-1) to end data input\n"); /* print to
screen instructions*/
while(data !=(-1)){
scanf("%d", &data); /* look for first data*/
push(data); /*push data to stack*/
}
while (data){
pop(data);
printf("reversed is %d ",data);
}
}
push(int val){
if (count>=MAXSTACK) return -1; /*stack full*/
else
stack[count++]=val;
return val;
}
pop(int *val){
if (count==0) return -1;
*val=stack[--count];
return *val;
}
newbie here
i am trying to push integers to a stack and when the input is complete, I
would like to pop them and print them out as they come off the stack.
TIA
Sandie
code here
#include <stdio.h>
#define MAXSTACK 1000
int push(int );
int pop (int );
int stack[MAXSTACK]; /* define stack size*/
int count; /* count for checking if stack full, data for the data to move
around the stack*/
void main(void){
int data;
printf("please input Data type (-1) to end data input\n"); /* print to
screen instructions*/
while(data !=(-1)){
scanf("%d", &data); /* look for first data*/
push(data); /*push data to stack*/
}
while (data){
pop(data);
printf("reversed is %d ",data);
}
}
push(int val){
if (count>=MAXSTACK) return -1; /*stack full*/
else
stack[count++]=val;
return val;
}
pop(int *val){
if (count==0) return -1;
*val=stack[--count];
return *val;
}