Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mominaamjad/swap-linked-list-nodes
Project to execute the swapping of any two nodes in a singly linked list. Includes methods for inserting and deleting elements.
https://github.com/mominaamjad/swap-linked-list-nodes
cpp data-structures linked-list semester-3
Last synced: 8 days ago
JSON representation
Project to execute the swapping of any two nodes in a singly linked list. Includes methods for inserting and deleting elements.
- Host: GitHub
- URL: https://github.com/mominaamjad/swap-linked-list-nodes
- Owner: mominaamjad
- Created: 2023-03-26T10:21:11.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-07-21T09:44:24.000Z (4 months ago)
- Last Synced: 2024-07-21T10:49:47.218Z (4 months ago)
- Topics: cpp, data-structures, linked-list, semester-3
- Language: C++
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Swap Linked List Nodes
code to execute swapping of any two nodes
# About
This menu-driven C++ program implements a singly linked list with the functionality to swap any two nodes, add nodes at the end, and delete nodes from the end.
## Features
- **Insert Value at End**: Adds a new node with the given value at the end of the list.
- **Delete Value from End**: Deletes the node at the end of the list.
- **Swap Nodes**: Swaps the mth node from the start with the nth node from the end.
- **Display Values**: Displays all the values in the list.## Code Overview
- **node**: A structure representing a node in the linked list.
```cpp
struct node {
int id;
node* next = NULL;
};
- **LinkedList**: A class containing methods to manipulate the linked list.* `insertEnd(int x)`: Inserts a node at the end of the list.
* `deleteEnd()`: Deletes the node at the end of the list.
* `swapNodes(int m, int n)`: Swaps the mth node from the start with the nth node from the end.
* `display()`: Displays all nodes in the list.