Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added documentation and README file to linked list folder, minor fixes to README #456

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be deleted. You can update .gitignore to add an entry for .DS_Store

Binary file not shown.
Binary file added .github/.DS_Store
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be deleted

Binary file not shown.
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out of scope for this PR. If you like you can create a new PR to suggest adding this GitHub action.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: SonarCloud
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build and analyze
runs-on: macos-latest
env:
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install sonar-scanner and build-wrapper
uses: SonarSource/sonarcloud-github-c-cpp@v2
- name: Run build-wrapper
run: |
build-wrapper-macosx-x86 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} xcodebuild
- name: Run sonar-scanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ handle it from there. :smile:
* [Coin change](cpp/include/algorithm/dynamic_programming/coin_change.hpp) :white_check_mark:
* [Longest decreasing subsequence](cpp/include/algorithm/dynamic_programming/longest_decreasing_subsequence.hpp) :white_check_mark:
* [Matrix chain multiplication](cpp/include/algorithm/dynamic_programming/matrix_chain_multiplication.hpp) :white_check_mark:
* Maximum sum contiguous subarray: [Kadane's algorithm](cpp/include/algorithm/dynamic_programming/kadane.hpp) :white_check_mark:
* Maximum sum contiguous subarray
* [Kadane's algorithm](cpp/include/algorithm/dynamic_programming/kadane.hpp) :white_check_mark:
* [Rod cutting](cpp/include/algorithm/dynamic_programming/rod_cutting.hpp) :white_check_mark:
* [Weighted activity selection](cpp/include/algorithm/dynamic_programming/weighted_activity_selection.hpp) :white_check_mark:

Expand All @@ -64,7 +65,7 @@ handle it from there. :smile:
* [Logarithmic time algorithm](cpp/include/algorithm/number_theory/fibonacci_efficient.hpp) :white_check_mark:
* [Perfect number check](cpp/include/algorithm/number_theory/perfect_number_check.hpp) :white_check_mark:
* Prime numbers
* [Primorial](include/algorithm/number_theory/primorial.hpp) :white_check_mark:
* [Primorial](cpp/include/algorithm/number_theory/primorial.hpp) :white_check_mark:
* [Sieve of Eratosthenes (simple)](cpp/include/algorithm/number_theory/sieve_of_eratosthenes.hpp) :white_check_mark:

* Searching
Expand Down
40 changes: 40 additions & 0 deletions cpp/include/data_structure/linked_list/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Linked List

The linked list is a dynamic data structure that contains elements not stored in contiguous memory. This means that the elements of the list must contain pointers to other elements in the list in order to form a chain of associations.
As a result of it being dynamic, the linked list can easily grow and shrink.
Common implementations of the linked list include stacks and queues, which often only need to access or remove elements from the front or end of a list.

### Contents

1. [doubly linked list](#1-doubly-linked-list)
2. [singly linked list](#2-singly-linked-list)

---

## 1. Doubly Linked List

The Doubly Linked List stores a list of elements that contain pointers to both the previous and next element in the list.
This implementation of the linked list allows for both forward and backward traversion, but it does require more memory than the Singly Linked List.


### Complexity

Time | Space
--------|-------------------
_O(N)_ | _O(1)_

where N is the number of elements.

## 2. Singly Linked List

The Singly Linked List stores a list of elements that contain a pointer to the next element in the list.
This implementation of the linked list allows for only forward traversion, but requires less memory than the Doubly Linked List.


### Complexity

Time | Space
--------|-------------------
_O(N)_ | _O(N)_

where N is the number of elements.
47 changes: 42 additions & 5 deletions cpp/include/data_structure/linked_list/doubly_linked_list.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
Doubly linked list
------------------
The doubly linked list is a data structure used to store a collection of elements.
Each element can be used to store data along with two pointers which point to the
previous and the next elements in the list.
The doubly linked list is very similar to the singly linked list, but the latter stores
only a single pointer to the next element and does not store a pointer to the previous element.
Certain advantages of using this list include traversal in both the forward and backward
directions and the ability to efficiently insert and delete new elements.
*/

#ifndef DOUBLY_LINKED_LIST_HPP
#define DOUBLY_LINKED_LIST_HPP

Expand All @@ -17,30 +29,48 @@ struct Node {
Node();

public:
/*
Constructor
-----------
*/
Node(const T value, Node<T> *const prev, Node<T> *const next) {
this->value = value;
this->prev = prev;
this->next = next;
}

/*
Copy Constructor
-----------
*/
Node(const Node<T> &n) {
this->value = n.value;
this->prev = n.prev;
this->next = n.next;
}

/*
Assignment operator
-------------------
Assigns the values of the RHS (right hand side) to the LHS (left hand side)
*/
Node<T> operator=(const Node<T> &rhs) {
this->value = rhs.value;
this->prev = rhs.prev;
this->next = rhs.next;
return *this;
}

/*
Destructor
----------
Setting the element's pointers to nullptr removes its association with the list
*/
~Node() {
this->prev = nullptr;
this->next = nullptr;
}

/*
Getters and setters
-------------------
*/
T get_value() {
return this->value;
}
Expand Down Expand Up @@ -110,13 +140,20 @@ class DoublyLinkedList {
void clear();
};

/*
Constructor
-----------
*/
template<class T>
DoublyLinkedList<T>::DoublyLinkedList() {
size = 0;
head = tail = nullptr;
}


/*
Destructor
----------
*/
template<class T>
DoublyLinkedList<T>::~DoublyLinkedList() {
clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ SinglyLinkedList<T>::SinglyLinkedList() {
/*
Destructor
----------

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This blank link can be removed.

*/

template<class T>
Expand Down