home *** CD-ROM | disk | FTP | other *** search
-
- // Main program for testing the Stack object
-
- #import <stdio.h>
- #import "Stack.h"
-
- main ( argc, argv )
- int argc;
- char *argv[];
- {
- id stack;
-
- printf ("\nCreate a Stack instance...\n");
- stack = [[Stack alloc] init]; //allocate and initialize
-
- printf("Print the stack...\n");
- [stack printStack]; //print it out
-
- printf ("Push 5.0, 10.0, then 15.0 ...\n"); //push 3 nos.
- [stack push:5.0];
- [stack push:10.0];
- [stack push:15.0];
-
- printf("Print the stack...\n");
- [stack printStack];
-
- printf("Top of stack is: %f\n", [stack top]); //show top of stack
-
- printf("Pop four times...\n"); //illustrate LIFO
- printf("Number popped: %f\n", [stack pop]);
- printf("Number popped: %f\n", [stack pop]);
- printf("Number popped: %f\n", [stack pop]);
- printf("Number popped: %f\n", [stack pop]); //empty stack will return 0.0
-
- printf("Print the stack...\n"); //show an empty stack
- [stack printStack];
-
- printf("Fill the stack again with 2.0, 4.0, 6.0, then 8.0...\n"); //refill
- [stack push:2.0];
- [stack push:4.0];
- [stack push:6.0];
- [stack push:8.0];
-
- printf("Print the stack...\n"); //show 4 numbers
- [stack printStack];
-
- printf("Top of stack is: %f\n", [stack top]); //show top of stack
-
- printf("Now empty the stack...\n"); //now empty it
- [stack empty];
-
- printf("Print the stack...\n"); //show an empty stack
- [stack printStack];
-
- printf("Now freeing the stack...\n"); //free it up
- [stack free];
-
- } // end of program
-