Created
September 25, 2011 12:28
-
-
Save domkck/1240561 to your computer and use it in GitHub Desktop.
DKStack and DKQueue example
This file contains 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
//Stack - FILO (first in, last out) | |
DKStack* stack = [[DKStack alloc] init]; | |
[stack push:foo]; //Push foo on the stack | |
[stack push:bar]; //Push bar on the stack | |
[stack pop]; //Pop top element (bar) from the stack | |
[stack top]; //Now returns foo | |
[stack pop]; //Pop top element (foo) from the stack | |
[stack isEmpty]; //Now returns YES | |
//Queue - FIFO (first in, first out) | |
DKQueue* queue = [[DKQueue alloc] init]; | |
[queue push:foo]; //Push foo to the queue | |
[queue push:bar]; //Push foo to the queue | |
[queue pop]; //Pop first element (foo) from the queue | |
[queue first]; //Now returns bar | |
[queue pop]; //Pop bar from queue | |
[queue isEmpty]; //Now returns YES |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment