Giter VIP home page Giter VIP logo

sllist's Introduction

sllist

Programmer's library for manupulate Single Linked List
Prototypes of functions in

sllist.h

Code of functions in

sllist.cpp

Example without the library

withoutSLL.cpp

Features

Examples of uses in
main.cpp

User functions prototypes in
myFuncts.h
Code in
myFuncts.cpp

Conform to g++
Building
make
This command produce test executable
./testSLL
Cleaning
make mrproper

Functions

Create a new list

Returns a pointer to a new, empty list. If allocation fails, returns nullptr.
sllist* sllist_create(void)

Destroy a list

Frees the memory of the list struct and all associated nodes.
void sllist_destroy(sllist* theIdx)

Prepend a node to the list

Adds a node to the front of the list. If allocation fails, returns -1, otherwise returns 0.
int sllist_push_front(sllist* theIdx, void* theData)

Append node to a list

Adds a node to the end of the list. If allocation fails, returns -1, otherwise returns 0.
int sllist_push_back(sllist* theIdx, void* theData)

Extract the first node

Remove the first node from the linked list, save a pointer to the data, free the node (but do not free the data itself), and return a pointer to the data so that it can be used. If the list is empty, returns nullptr.
void* sllist_pop_front(sllist* theIdx)

Extract the last node

Remove the last node from the linked list, save a pointer to the data, free the node (but do not free the data itself), and return a pointer to the data so that it can be used. If the list is empty, returns nullptr.
void* sllist_pop_back(sllist* theIdx)

Step through a list

Changes the current node to the node after the current node. Returns 1 if the current node is nullptr.
int sllist_step(sllist* theIdx)

Access data by index

Returns a pointer to the payload of the node at the location specified by the passed index value. The passed index value is interpreted as an offset from index zero, the first node of the list. Returns nullptr if the list is empty or the index is out of range.
void* sllist_read_index(sllist* theIdx, int theRow)

Insert a node after the node at the specified index

Adds a node after the passed node. If allocation fails, returns -1. If the node doesn't exist in the list, returns 1. Otherwise, returns 0.
int sllist_insert_after(sllist* theIdx, int theRow, void* theData)

Extract a node after the node at the specified index

Remove the specified node from the linked list, save a pointer to the data, free the node (but do not free the data itself), and return a pointer to the data so that it can be used. If the list is empty or the node doesn't exist in the list, returns nullptr. Attempting to extract after the tail will also return nullptr.
void* sllist_extract_after(sllist* myIdx, int theRow)

Acknowledgements

Very largely inspired by a "code review" on StackExchange.

sllist's People

Contributors

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