Giter Site home page Giter Site logo

basemax / arraylistc Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 53 KB

This is a simple implementation of an ArrayList in C using a struct, a pointer to the struct and a pointer to the array. The array is static and the size of the array is defined when the ArrayList is created.

License: GNU General Public License v3.0

C 100.00%
array arraylist arraylist-c c c-array array-c

arraylistc's Introduction

ArrayList C

This is a simple implementation of an ArrayList in C using a struct, a pointer to the struct and a pointer to the array. The array is static and the size of the array is defined when the ArrayList is created.

Functions

  • ArrayList* ArrayCreate(int n): Creates an ArrayList with a size of n.

  • void ArrayAppendFirst(ArrayList* list, int value): Add an element to the beginning of the list.

  • void ArrayAppendLast(ArrayList* list, int value): Appends a value to the end of the array.

  • void ArrayAppend(ArrayList* list, int value, int index): Appends a value to the array at the specified index.

  • void ArrayDelete(ArrayList* list, int index): Deletes the element at the given index.

  • void ArrayDeleteFirst(ArrayList* list): Deletes the first element of the array.

  • void ArrayDeleteLast(ArrayList* list): Deletes the last element of the array.

  • void ArrayPrint(ArrayList* list): Prints the array

  • void ArrayFree(ArrayList* list): Frees the memory

  • char* ArrayToString(ArrayList* list): Returns a string representation of the array

Usage

// Create an array list with maximum 10 value capacity.
ArrayList* list = ArrayCreate(10);

// Append a value to the last of the array list.
ArrayAppendLast(list, 10);
ArrayAppendLast(list, 20);
ArrayAppendLast(list, 30);
ArrayAppendLast(list, 40);

// Append a value to the first of the array list.
ArrayAppendFirst(list, 5);

// Append a value to the array list at the specified index.
ArrayAppend(list, 25, 2);

// Print the array list.
ArrayPrint(list);

// Delete a value from the array list at the specified index.
ArrayDelete(list, 3);

// Delete a value from the first of the array list.
ArrayDeleteFirst(list);

// Delete a value from the last of the array list.
ArrayDeleteLast(list);

// Print the array list.
ArrayPrint(list);

And the output is:

5 10 25 20 30 40
10 25 30

© Copyright Max Base, 2022

arraylistc's People

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.