An open API service indexing awesome lists of open source software.

https://github.com/abdullahselek/linkedlistcxx

C++ generic LinkedList implementation.
https://github.com/abdullahselek/linkedlistcxx

cpp generic library linkedlist

Last synced: 15 days ago
JSON representation

C++ generic LinkedList implementation.

Awesome Lists containing this project

README

        

# linkedlistcxx

[![Build Status](https://travis-ci.org/abdullahselek/linkedlistcxx.svg?branch=master)](https://travis-ci.org/abdullahselek/linkedlistcxx)
[![Build status](https://ci.appveyor.com/api/projects/status/5ku2a2q2kjcvlr1u?svg=true)](https://ci.appveyor.com/project/abdullahselek/linkedlistcxx)

LinkedList implementation with C++ as a library.

## Building Repository

To build the repository you need CMake. You can download from [here](https://cmake.org/download/).
You can create a shortcut ```cmake``` command for macOS as below

```
sudo mkdir -p /usr/local/bin
sudo /Applications/CMake.app/Contents/bin/cmake-gui --install=/usr/local/bin
```

After cloning repository to your own local machine go to project root folder and run

```
cmake .
```

and then

```
cmake --build .
```

to run unit tests for UNIX machines

```
cd test
./tests --gtest_color=yes
```

and for Windows machines

```
cd test/Debug/
tests.exe --gtest_color=yes
```

## Sample Usage

Initiate linkedlist as below

```
LinkedList *linkedList = new LinkedList();
```

Initiation of Node

```
std::string strNext("next");
std::string strNode("node");

Node *next = new Node(strNext, nullptr);
Node *node = new Node(strNode, next);
```

Adding first node

```
std::string strFirst("first");
Node *first = new Node(strFirst, nullptr);
linkedList->addFirst(first);
```

Getting first node's data

```
std::string data = linkedList->getFirst();
```

Removing head from LinkedList

```
std::string headData = linkedList->removeFirst()
```

Adding last node

```
std::string strLast("last");
Node *last = new Node(strLast, nullptr);
```

Adding data as node

```
std::string last("last");
std::string head("head");
linkedList->add(nullptr, head);
linkedList->add(linkedList->getHead(), last);
```

Clear LinkedList

```
linkedList->clear();
```

Searching for node data

```
std::string mid("mid");
Node *foundNode = linkedList->searchNode(mid);
```

Delete node

```
std::string mid("mid");
Node *node = linkedList->searchNode(mid);
bool isDeleted = linkedList->deleteNode(node);
```