Skip to content

Commit 59eee36

Browse files
committed
more singly linked lists
1 parent 5c1740d commit 59eee36

3 files changed

Lines changed: 108 additions & 2 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
path: "/singly_linked_list_creation"
3+
date: "October 5, 2020"
4+
title: "Singly - Creation"
5+
author: "Bipin karki"
6+
language: "Python"
7+
difficulty: "Easy"
8+
img: "https://images.pexels.com/photos/4073072/pexels-photo-4073072.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"
9+
question: Create a Singly Linked list to quickly add nodes.
10+
11+
Note: Random.
12+
descriptionImage: "https://cdn.programiz.com/sites/tutorial2program/files/linked-list-concept_0.png"
13+
description: " A linked list data structure includes a series of connected nodes. Here, each node store the data and the address of the next node. Time complexity for Search is O(n) and for insert and delete is O(1) while the space complexity is O(n).
14+
The main advantages of using a linked list are Dynamic memory allocation,
15+
Implemented in stack and queue,
16+
In undo functionality of softwares,
17+
Hash tables, Graphs.
18+
The structure of singly Linked list is given below:
19+
"
20+
21+
---
22+
23+
24+
class Node:
25+
def __init__(self,data):
26+
self.data = data
27+
self.next = None
28+
class Insert:
29+
def __init__(self,n):
30+
self.head = None
31+
self.n = n
32+
self.insert_multiple_nodes()
33+
def insert_multiple_nodes(self):
34+
for i in range(1, self.n+1):
35+
if self.head == None:
36+
self.head = self.insert_node(i, self.head)
37+
continue
38+
self.insert_node(i, self.head)
39+
def insert_node(self,data,head):
40+
if head == None:
41+
return Node(data)
42+
temp = head
43+
while(temp.next!=None):
44+
temp= temp.next
45+
temp.next = Node(data)
46+
def print_list(self):
47+
temp = self.head
48+
while temp!=None:
49+
print(temp.data,end="->")
50+
temp = temp.next
51+
print("Null")
52+
if __name__ == "__main__":
53+
i = Insert(12)
54+
i.print_list()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
path: "/singly_linked_list_insertions"
3+
date: "October 5, 2020"
4+
title: "Singly - Insertions"
5+
author: "Bipin karki"
6+
language: "Python"
7+
difficulty: "Easy"
8+
img: "https://images.pexels.com/photos/3758105/pexels-photo-3758105.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"
9+
question: Create a class with all types of insertion on singly linked list.
10+
11+
Note: Random.
12+
descriptionImage: "https://cdn.programiz.com/sites/tutorial2program/files/linked-list-concept_0.png"
13+
description: " A linked list data structure includes a series of connected nodes. Here, each node store the data and the address of the next node. Time complexity for Search is O(n) and for insert and delete is O(1) while the space complexity is O(n).
14+
The main advantages of using a linked list are Dynamic memory allocation,
15+
Implemented in stack and queue,
16+
In undo functionality of softwares,
17+
Hash tables, Graphs.
18+
The structure of singly Linked list is given below:
19+
"
20+
21+
---
22+
23+
24+
from singly_linked_list import Insert #I have imported my own modules.
25+
from singly_linked_list import Node
26+
27+
class Insert_All_Places:
28+
def __init__(self, n):
29+
self.number_singly = Insert(n)
30+
def begining(self, data):
31+
temp = self.number_singly.head
32+
self.number_singly.head = Node(data)
33+
self.number_singly.head.next = temp
34+
def end(self,data):
35+
temp = self.number_singly.head
36+
while temp.next!=None:
37+
temp = temp.next
38+
temp.next = Node(data)
39+
def after_node(self, prev, data):
40+
if prev==None:
41+
print("Prev is None")
42+
return
43+
new_node = Node(data)
44+
new_node.next = prev.next
45+
prev.next = new_node
46+
if __name__ == "__main__":
47+
singly_list = Insert_All_Places(10)
48+
singly_list.begining(2100)
49+
singly_list.number_singly.print_list()
50+
singly_list.end(900)
51+
singly_list.number_singly.print_list()
52+

src/pages/programs/singly_linked_list.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
path: "/singly_linked_list"
2+
path: "/singly_linked_list_duplicates"
33
date: "September 9, 2020"
4-
title: "Singly Linked List"
4+
title: "Singly - Duplicates"
55
author: "Bipin karki"
66
language: "Python"
77
difficulty: "Easy"

0 commit comments

Comments
 (0)