Code Monkey home page Code Monkey logo

data-structs's Introduction

Generic Data Structures

Generic implementation of data structures in C.
For the moment we have implemented:

  1. Array List
  2. Hash Table

This API is open source and made by me, José Pereira and Henrique Faria.

About

How to compile & run:

  1. make
  2. ./main

Project structure:

src/ (contains .c files)
include/ (contains .h files)

Example of usage:

void printPEOPLE(TAD_ARRAY_LIST people) {
	int size = getArraySize(people);
	for(int i=0; i<size; i++) {
		TAD_PERSON p = (TAD_PERSON) getElem(people, i);
		printPERSON(p);
	}
}


void freePEOPLE(TAD_ARRAY_LIST people) {
	int size = getArraySize(people);
	for(int i=0; i<size; i++) {
		TAD_PERSON p = (TAD_PERSON) getElem(people, i);
		freePERSON(p);
	}
	free_ARRAY_LIST(people);
}


void ArrayListUsage() {

	TAD_PERSON musk = PERSON(0, "Elon Musk", 34);
	TAD_PERSON turing = PERSON(1, "Alon Turing", 41);

	// Create ArrayList named people
	TAD_ARRAY_LIST people = ARRAY_LIST(INITIAL_ARRAYLIST_DIM);
	
	// add elements to ArrayList
	addElem(people, musk);
	addElem(people, turing);

	// print all elements inside ArrayList
	printPEOPLE(people);

	// free all elements and ArrayList structure
	freePEOPLE(people);
}

READ ME (VERY IMPORTANT):

Because this implementation is generic we can not guess what data type is going to be stored in each data structure so it's user task to allocate and free memory created by him. The free() method for each data structure only frees the structure itself not the elements added by user.
This is demonstrated in API usage above if you notice the user had to implement printPEOPLE() and freePEOPLE() because it's user specific code.
The freePEOPLE() frees user created data one by one and after calls free() function from ArrayList structure.

To sum up you should (must) implement bellow interface for each data:

  1. print(StructureName)()
  2. free(StructureName)()

FAQ

What data type can each data structure store?

Any data type (int* , float*, char*, strucutres implemented by user, etc.) can be stored.
This is guaranteed because we use void* data type wich means any pointer can be stored.

data-structs's People

Contributors

ricardopetronilho98 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.