Created
June 21, 2014 10:00
-
-
Save kaleocheng/65b0320ba6291a9db188 to your computer and use it in GitHub Desktop.
Stack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<assert.h> | |
#include"stack.h" | |
#define MAX 10 | |
static STACK_TYPE arry[MAX]; | |
static int topElement = -1; | |
#include"StackOption.c" | |
int main() | |
{ | |
push(2); | |
push(4); | |
push(6); | |
push(8); | |
push(10); | |
printf("%d ",top()); | |
pop(); | |
printf("%d ",top()); | |
pop(); | |
printf("%d ",top()); | |
pop(); | |
printf("%d ",top()); | |
pop(); | |
printf("%d ",top()); | |
printf("\n"); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define STACK_TYPE int | |
void push(STACK_TYPE value); | |
void pop(void); | |
STACK_TYPE top(void); | |
int isFull(void); | |
int isEmpty(void); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
push | |
*/ | |
void push(STACK_TYPE value) | |
{ | |
assert(!isFull()); | |
topElement += 1; | |
arry[topElement] = value; | |
} | |
/* | |
pop | |
*/ | |
void pop(void) | |
{ | |
assert(!isEmpty()); | |
topElement -= 1; | |
} | |
/* | |
top | |
*/ | |
STACK_TYPE top(void) | |
{ | |
assert(!isEmpty()); | |
return(arry[topElement]); | |
} | |
/* | |
isFull | |
*/ | |
int isFull(void) | |
{ | |
return topElement == MAX-1; | |
} | |
/* | |
isElement | |
*/ | |
int isEmpty(void) | |
{ | |
return topElement == -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment