GithubHelp home page GithubHelp logo

linked-list's Introduction

linked-list

Run on Repl.it

Description

A singly linked list C++ library

Documentation

See test.cpp for examples.
template <typename T> partially specialized for T or T *.

Initialization examples

LinkedList<int> list = LinkedList<int>();
LinkedList<Card *> list = LinkedList<Card *>();

Constructor

LinkedList()
Create a new LinkedList with no data.

Copy Constructor

LinkedList(LinkedList const &source)
Create a new LinkedList with copy of data from source.
Parameters:
  LinkedList const &source: list to copy data from.

Destructor

~LinkedList() Calls clear().

Clear

void clear()
Clears and deletes all nodes and data.

Add

void add(T data)
void add(T *data)
Adds a new node with specified data to the end of the linked list.
Parameters:
  T data or T *data: primitive data or pointer to new data to be stored

Size

int size()
Returns the number of nodes.
Returns:
  int: the size of the linked list.

Set

void set(const int index, T data)
void set(const int index, T *data)
Replaces the data of the node at the specified index with new data.
Parameters:
  const int index: index of desired node
  T data or T *data: primitive data or pointer to new data to be stored

Insert

void insert(const int index, T data)
void insert(const int index, T *data)
Inserts a new node and new data before the specified index.
Parameters:
  const int index: index of node to be after new node
  T data or T *data: primitive data or pointer to new data to be stored

Remove

void remove(const int index)
Removes the node and data at the specified index.
Parameters:
  const int index: index of node to be deleted

Empty

bool empty()
Returns true if the linked list has no elements in it.
Returns:
  bool: whether the linked list is empty

Swap

void swap(const int index1, const int index2)
Switches the data of the nodes at the specified indexes.
Parameters:
  const int index1: index of the first specified node
  const int index2: index of the second specified node

Sub List

LinkedList<T> * subList(const int start, const int length)
Creates and returns a new list containing data from a sub-range of the linked list.
Parameters:
  const int start: starting index of the sub-range
  const int length: length of the sub-range (start + length is not included in the new linked list)
Returns:
  LinkedList *: a pointer to the new linked list

Overload []

T operator[](const int index)
T *operator[](const int index)
Access data at the given index.
Parameters:
  const int index: index of desired node
Returns:
  T or T *: primitive data or pointer to data

Overload <<

std::ostream &operator<<(std::ostream &os, const LinkedList<T> &list)
std::ostream &operator<<(std::ostream &os, const LinkedList<T *> &list)
Print the data in the list to the ostream. The class in a pointer list T * must also overload the << operator.
Parameters:
  std::ostream &os: ostream data being added to
  const LinkedList<T> &list or const LinkedList<T *> &list: list to be printed
Returns: std::ostream &: ostream with added data

License

GPL-3.0 License

linked-list's People

Contributors

ttury avatar tyhil avatar

Stargazers

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