stack1 - } void Stack_Push(Stack *S, int d) { if...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Stack Implementation in C #define STACK_MAX 100 struct Stack { int data[STACK_MAX]; int size; }; typedef struct Stack Stack; void Stack_Init(Stack *S) { S->size = 0; } int Stack_Top(Stack *S) { if (S->size == 0) { fprintf(stderr, "Error: stack empty\n"); return -1; } return S->data[S->size-1];
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } void Stack_Push(Stack *S, int d) { if (S->size < STACK_MAX) S->data[S->size++] = d; else fprintf(stderr, "Error: stack full\n"); } void Stack_Pop(Stack *S) { if (S->size == 0) fprintf(stderr, "Error: stack empty\n"); else S->size--; }...
View Full Document

This note was uploaded on 12/14/2011 for the course EECS 6.837 taught by Professor Durand during the Fall '03 term at MIT.

Page1 / 2

stack1 - } void Stack_Push(Stack *S, int d) { if...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online