Author Archives: Mohamed

How to read multiple binary files in one array

vector<unsigned char> readFile(int count, ...) {
    va_list argptr;
    va_start(argptr, count);
    vector<unsigned char> data;
    for (int i = 0; i < count; i++) {
        char* name = va_arg(argptr, char*);
        streampos begin, end;
        ifstream file(name, ios::binary|ios::in|ios::ate);
        if (file.is_open()) {
            int size = int(file.tellg());
            file.seekg(0, ios::beg);
            char* memblock = new char[size];
  , size);
            data.insert(data.end(), memblock, memblock + size);
            delete[] memblock;
            cout << "Unable to open file: \"" << name << "\"" << endl;
    return data;

Trees: Introduction

Trees are very useful data structures. With little effort, we can think of several situations trees are useful for. Think of ancestry trees, your computer file system, and how about a tree of all possible solutions to a chess game.


In their general form, trees are data structures in which data is stored in nodes. Nodes are connected together with edges.

Continue reading


Queues are dreadful in real-life when you have to wait in line for an hour or two. But in data structures, they are very useful and simple to implement.

Queues follow a very simple design concept: First-In-First-Out or FIFO. In other words, items arrive first into a queue are processed first.

Queues are useful to use as a buffers to store system input data until the system catches up and asks for more data from the queue to process.

FIFO queue featuring enqueue() and dequeue() methods

FIFO queue featuring enqueue() and dequeue() methods

Continue reading


A stack is a data structure that resembles a stack of of boxes. The first box you put on the floor is the last to be removed, and the last box you stack up is the first to be removed. This is what we call First In Last Out or FILO.


  • Push is the operation to add items to a stack.

    Items are added to the stack from one end

    Items are added to the stack from one end

    Continue reading

C++: Structures, Cont’d

In a previous post we discussed how data structures can be useful in C++ to categorize relevant information together.

We implemented the following example for a driver’s license structure:

struct DriversLicense {
        int number;
        string name;
        string address;
        we'll cover DOB later 
        (hint: think of it as a struct.)
} MyLicense;

Continue reading

C++: Structures

Remember our driver’s license example we discussed in an earlier post. A license holds several pieces of information:

License Number: 12345
Name: Arthur Dent
Address: Near Dean Street
Date Of Birth: 03/08/1978

When a structure is mentioned in C++ context, in fact, we are talking about a feature of the language that enables the programmer to create data structures that can represent data grouping like what you would find on a license, library card, price tag for a product, a card game card, etc.

Continue reading