@@ -3,22 +3,15 @@ def __int__(self,data):
3
3
self .data = data #given data
4
4
self .next = None #given next to None
5
5
class Linked_List :
6
+
6
7
pass
7
- def insert_tail (Head ,data ):#insert the data at tail
8
- tamp = Head #create a tamp as a head
9
- if (tamp == None ):#if linkedlist is empty
10
- newNod = Node ()#create newNode Node type and given data and next
11
- newNod .data = data
12
- newNod .next = None
13
- Head = newNod
8
+
9
+ def insert_tail (Head ,data ):
10
+ if (Head .next is None ):
11
+ Head .next = Node (data )
14
12
else :
15
- while tamp .next != None :#find the last Node
16
- tamp = tamp .next
17
- newNod = Node ()#create a new node
18
- newNod .data = data
19
- newNod .next = None
20
- tamp .next = newNod #put the newnode into last node
21
- return Head #return first node of linked list
13
+ insert_tail (Head .next , data )
14
+
22
15
def insert_head (Head ,data ):
23
16
tamp = Head
24
17
if (tamp == None ):
@@ -32,16 +25,18 @@ def insert_head(Head,data):
32
25
newNod .next = Head #put the Head at NewNode Next
33
26
Head = newNod #make a NewNode to Head
34
27
return Head
35
- def Print ( Head ): #print every node data
36
- tamp = Node ()
28
+
29
+ def printList ( Head ): #print every node data
37
30
tamp = Head
38
31
while tamp != None :
39
32
print (tamp .data )
40
33
tamp = tamp .next
34
+
41
35
def delete_head (Head ):#delete from head
42
36
if Head != None :
43
37
Head = Head .next
44
38
return Head #return new Head
39
+
45
40
def delete_tail (Head ):#delete from tail
46
41
if Head != None :
47
42
tamp = Node ()
@@ -50,12 +45,6 @@ def delete_tail(Head):#delete from tail
50
45
tamp = tamp .next
51
46
tamp .next = None #delete the last element by give next None to 2nd last Element
52
47
return Head
53
- def isEmpty (Head ):
54
- if (Head == None ):#check Head is None or Not
55
- return True #return Ture if list is empty
56
- else :
57
- return False #check False if it's not empty
58
-
59
-
60
-
61
48
49
+ def isEmpty (Head ):
50
+ return Head is None #Return if Head is none
0 commit comments