Thread: data structures
View Single Post
  #1  
Old 03-19-2009, 08:24 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
data structures

boredom struck and I couldn't really find anything involving queues and stacks on the wiki (ActionMap has a push and pop which confused me) so I wrote up a queue real quick.

the most practical use I can think of for this right now is a spar system, where players joining the line are pushed on the queue, and you use a pop to get who's next in line.

I'll add a stack and some other data structures potentially tomorrow when I'm not tired.

queue:
PHP Code:
public function onCreated()
{
  
this.data = {null};
}

public function empty()
{
  if (
front() == null)
    return 
true;
  return 
false;
}

public function 
front()
{
  if(
this.data[0] == null)
    return 
null;
  else
    return 
this.data[0];
}

public function 
enqueueobj)
{
  
this.data.addobj);
}

public function 
dequeue()
{
  
this.data.remove(this.data[0]);
}

public function 
pushobj)
{
  
enqueue(obj);
}

public function 
pop()
{
  
temp.ret front();
  
dequeue();
  return 
ret;

Reply With Quote