list, queue, stack

implement the list, queue, stack data structures in matlab
5.1K Downloads
Updated 5 May 2011

View License

The files implement the list, queue, stack data structures in matlab, and the queue and stack are a litter faster than the java's alternatives.

CStack define a stack data strcuture

It likes java.util.Stack, however, it could use CStack.content() to
return all the data (in cells) of the Stack, and it is a litter faster
than java's Stack.

s = CStack(c); c is a cells, and could be omitted
s.size() return the numble of element
s.empty() return whether the stack is empty
s.push(el) push el to the top of stack
s.pop() pop out the top of the stack, and return the element
s.top() return the top element of the stack
s.remove() remove all the elements in the stack
s.content() return all the data of the stack (in the form of a
cells with size [s.size(), 1]

CQueue define a queue data strcuture

It likes java.util.Queue, however, it could use CQueue.content() to
return all the data (in cells) of the Queue, and it is a litter faster
than java's Queue.

q = CQueue(c); c is a cells, and could be omitted
s.size() return the numble of element
s.empty() return whether the qeueu is empty
s.push(el) push el to the top of qeueu
s.pop() pop out the the beginning of queue, and return the element
s.front() return the the the beginning element of the qeueu
s.back() return the the the rear element of the qeueu
s.remove() remove all data from the queue
s.content() return all the data of the queue (in the form of a
cells with size [s.size(), 1]

update 2011-05-05
1. add an method "isempty" to determine if the stack and queue is emtpy, and the method "emtpy" is to remove the content of the stack and queue. (thanks to Vojtech)
2. throw a warning when top an empty stack, and back, front an empty queue. throw an error when pop an empty stack and queue. (Thanks to Derek)

Cite As

Zhiqiang Zhang (2024). list, queue, stack (https://www.mathworks.com/matlabcentral/fileexchange/28922-list-queue-stack), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Oil, Gas & Petrochemical in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.1.0.0

1. add an method "isempty"
2. throw a warning when top an empty stack, and back, front an empty queue. throw an error when pop an empty stack and queue. (Thanks to Derek)

1.0.0.0