Skip to content

This project implements a Sorted Linked List that maintains its elements in sorted order using insertion sort logic. The list supports insertion, deletion, overloaded operators, and proper memory management.

License

GeorgeMalakM/Sorted_Linked_List

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📌 Sorted Linked List

📜 Description

This project implements a Sorted Linked List that maintains its elements in sorted order using insertion sort logic. The list supports insertion, deletion, overloaded operators, and proper memory management.

✨ Features

  • Insertion (insert(n)): Adds n while keeping the list sorted.
  • Deletion (remove(n)): Removes the element at index n (0-based index). If n is out of bounds, no changes occur.
  • Overloaded Operators:
    • << (Output Operator): Prints the linked list in a formatted way.
    • [] (Index Operator): Returns the element at a given index. If out of bounds, an exception is thrown.
  • Memory Management: Ensures proper deallocation of memory when deleting nodes or destroying the list.

🏗️ Usage & Example Test Cases

Inserting Elements into the Sorted Linked List

L.insert(5);    // L = [5]
L.insert(8);    // L = [5, 8] 

L.insert(7);    // L = [5, 7, 8] 
L.insert(6);    // L = [5, 6, 7, 8] 
L.insert(6);    // L = [5, 6, 6, 7, 8] 
cout << L;      // Output: [5, 6, 6, 7, 8]

Accessing Elements Using Index Operator

cout << L[2];  // Output: 6 
cout << L[10]; // Throws out_of_range exception 

Deleting Elements from the Linked List

// Starting List: L = [5, 6, 6, 7, 8]
L.remove(0);   // L = [6, 6, 7, 8] 
cout << L;
// Output: [6, 6, 7, 8]

L.remove(100); // No change (out of bounds) 
cout << L;     
// Output: [6, 6, 7, 8] 

L.remove(2);   // L = [6, 6, 8] 
cout << L;
// Output: [6, 6, 8] 

L.remove(2);   // L = [6, 6] 
cout << L;
// Output: [6, 6] 

👨‍💻 Contributing

Contributions are welcome! Feel free to fork the repo and submit a pull request.

✍️ Authors

📜 License

This project is licensed under the MIT License.


Developed with ❤️ in C++

About

This project implements a Sorted Linked List that maintains its elements in sorted order using insertion sort logic. The list supports insertion, deletion, overloaded operators, and proper memory management.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5