Skip to content

Instantly share code, notes, and snippets.

@domkck
Created September 25, 2011 12:28
Show Gist options
  • Save domkck/1240561 to your computer and use it in GitHub Desktop.
Save domkck/1240561 to your computer and use it in GitHub Desktop.
DKStack and DKQueue example
//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