This is very simple implementaion of Data Structure like Stack and Singly Linked List
Main Data Structures collections:-
Stack, Singly LinkedList, Doubly LinkedList, SinglyCirclular LinkedList, DoublyCircular LinkedList.
Note:- if you initialize the stack size to 5 and you push only 3 element or less then 5 element then rest of the stack will print as 0 because initially all the value in stack is 0.
---
In linked list I implement singly, doubly, singlyCircular.
-
In Singly Linked List you can use so many methods, here is the list:-
1) len()
2) is_empty()
3) traverse()
4) insertAtHead(val)
5) insertAtTail(val)
6) insertAtPos(val, pos)
7) deleteHead()
8) deleteTail()
9) deleteAtPosition(pos)
10) insertAfter(val, newVal)
11) insertBefore(val, newVal)
12) mergeTwoLL(l1, l2)
13) get_tail()
14) get_head()
Here is the exmaple
Stack
from DScollection import *
s1 = Stack(5)
s1.push(1)
s1.push(2)
s1.push(3)
s1.push(4)
s1.push(5)
s1.pop()
s1.peek()
s1.isEmpty()
s1.printStack()
Singly Linked List
from DScollection import *
l1 = SinglyLL()
l2 = SinglyLL()
l1.insertAtTail(1)
l1.insertAtTail(2)
l1.insertAtTail(3)
l1.traverse()
l2.insertAtTail(4)
l2.insertAtTail(5)
l2.insertAtTail(6)
l2.traverse()
merged_list = SinglyLL()
merged_list.mergeTwoLL(l1, l2)
merged_list.traverse()
len(merged_list)
I will update this with all the data structure with ready to use, stay updated.
Change Log
0.0.8 (23/09/2024)
-Eighth Release
-Add updates.