Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/theroyakash/cds
Data structures using C
https://github.com/theroyakash/cds
Last synced: 1 day ago
JSON representation
Data structures using C
- Host: GitHub
- URL: https://github.com/theroyakash/cds
- Owner: theroyakash
- License: bsd-3-clause
- Created: 2021-08-26T06:39:54.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-05T16:24:53.000Z (almost 3 years ago)
- Last Synced: 2024-05-02T03:41:39.893Z (6 months ago)
- Language: C
- Size: 95.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# CDS
C data structures and algorithm implementation from scratch. Available data structures are the followings, more coming soon.
| API | Type |
|--------------------|-----------------|
| Linked List | Data Structures |
| Tree | Data Structures |
| Binary Search Tree | Data Structures |## Linked List Reference
#### Creating a new linkedlist node
```C
LinkedListNode n1, n2, n3;
```| Data structure | Type | Description |
| :-------- | :------- | :------------------------- |
| `LinkedListNode` | `typedef struct LinkedListNode` | **Creates a** new LinkedListNode |#### Setting few nodes and their arrangements
| Linked List Attribute | Type | Description |
| :-------- | :------- | :-------------------------------- |
| `.value` | `int` | Integer Value at a Node |
| `.next` | `*LinkedListNode` | Pointer to the next linked list node |```C
n1.value = 10;
n1.next = &n2;n2.value = 22;
n2.next = &n3;n3.value = 67;
n3.next = NULL;
```### Other way of adding new elements
#### Using `addNodeAtBegining()` and `addNodeAtEnd()` method
```C
LinkedListNode *newHead = addNodeAtBegining(&n1, 176);
newHead = addNodeAtBegining(&n1, 176);
newHead = addNodeAtBegining(newHead, 44);
newHead = addNodeAtBegining(newHead, 16);
newHead = addNodeAtBegining(newHead, 51);
newHead = addNodeAtBegining(newHead, 753);addNodeAtEnd(newHead, 88);
addNodeAtEnd(newHead, 34);
addNodeAtEnd(newHead, 55);```
#### Printing the total Linked List
```C
PRETTY_PRINT_LL(newHead);
```#### Output
```text
753 --> 51 --> 16 --> 44 --> 176 --> 10 --> 22 --> 67 --> 88 --> 34 --> 55 --> NULL
```### Complete Set of Linked List Functions and APIs
| Functions | Arguments | Return Type | Description |
|----------------------|----------------------------------------------|----------------------------------------------------------|---------------------------------------------------------------------|
| `PRETTY_PRINT_LL` | `LinkedListNode *nodeBase` Base Node Pointer | `void` | Prints the linked list in a pretty order |
| `*addNodeAtBegining` | `LinkedListNode *currentHead, int value` | `*LinkedListNode` Pointer to the new head | Adds new node at the begining and returns a pointer to the new head |
| `*addNodeAtEnd` | `LinkedListNode *head, int value` | `*LinkedListNode` Pointer to the tail (newly added node) | Adds new node at the end and returns the tail pointer |
| `*deleteHeadNode` | `LinkedListNode *head` Head of the List | `*LinkedListNode` Pointer to the new head | Delete the head node from the linked list, return the new head |## Authors
- [@theroyakash](https://www.github.com/theroyakash)
## ContributingContributions are always welcome! Please create a new PR.
## License[Apache License 2.0](https://github.com/theroyakash/CDS/blob/main/LICENSE/)