Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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.

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.