Skip to topic | Skip to bottom
Bennington College
r1.14 - 25 Feb 2006 - 14:26 - JoeHolt

Start of topic | Skip to actions
Look for:
  • bugs
  • limitations
  • potential crashes

Lists

int years[10];                      // Declaring storage for the list
int num_years;

num_years = 0;                      // Initializing the list

years[num_years] = y;               // Adding an element to the list
num_years++;

for (i = 0; i < num_years; ++i) {   // Iterating through the list
   years[i] ...
}

Queues

int line[10];                       // Declaring storage for the queue
int start, end;

head = 0;                           // Initializing the queue
tail = 0;

line[tail] = p;                     // Adding an element to the queue
tail++;

p = line[start];                    // Removing an element from the queue
start++;

Stacks

int stack[10];                      // Declaring storage for the stack
int stack_pointer;

stack_pointer = 0;                  // Initializing the stack

stack[stack_pointer] = v;           // Pushing an element onto the stack
stack_pointer++;

--stack_pointer;                    // Popping an element off the stack
v = stack[stack_pointer];