Data Structures
Queues:
It follow a FIFO (First-In-First-Out) property.
It has 2 operations:
- Enqueue
- Dequeue
Enqueue code:
const int CAPACITY = 50;
typedef struct
{
person people[CAPACITY];
int size;
} queue;
constvariable of int type called capacity , of 50;- Define a structure
- It has an array of persons called people
- variable size to keep track of how big the queue is
!NOTE: The capacity is hardcodes the capacity of 50, so it can't grow dynamically.
Stack
It follows a LIFO property (last-in-first-out). (Gmail -->Where new emails end up at the top)
It was 2 properties:
- push
- pop
const int CAPACITY = 50;
typedef struct
{
person people[CAPACITY];
int size;
} stack;
Same as the queue implementation , but because the last element will finish at index 0 of the array, it will be easier to pop and push.
dictionaries
Another abstract data type that follow a key-value type of association, which is its main property.
- Contacts app in an iphone
array
A chuck of memory where values can be stored contiguously.
(Exercises start from list.c)
hardcoded array:
#include <stdio.h>
int main(void)
{
int list[4];
list[0] = 1;
list[1] = 2;
list[2] = 3;
list[3] = 4;
for (int i = 0; i < 4; i++)
{
printf("%i\n", list[i]);
}
}