Code Monkey home page Code Monkey logo

c-list-class's Introduction

List class in C !

Hi! It's a small project for fun to try to implement a class in C. I took the a one way linked list class as challenge. The list store copies of the items (not references).

How to use it

After you included List.h, you can:

  • create a new list of any type,
  • add new items into the front of the list with list->push(...)
  • get the last item with list->pop(...)
  • delete the list with delete()

Example

#include "List.h"

// define a new "complex" structure
typedef struct myStruct
{
    int int_field;
    double double_field;
    char *pChar_field;
    char string_field[128];
} myStruct_t;

// Create the list
List *list = newList(myStruct_t);

// push a new item in the list
myStruct_t value;
value.int_field = 1111;
value.double_field = 35.98;
value.pChar_field = "pChar_field 1";
strcpy(value.string_field, "string_field 1");
list->push(list, &value);

// Get the last item
myStruct_t value2 = {0};
list->pop(list, &value2);
printf("value : int_field = %d, double_field = %f, pChar_field = %s, string_field = %s\n",
    value2.int_field, value2.double_field, value2.pChar_field, value2.string_field);

// Delete the list
list->delete(&list);

How to build

Build the project with "make"

c-list-class's People

Contributors

nonprenom avatar

Watchers

 avatar  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.