SlideShare a Scribd company logo
1 of 4
Download to read offline
class LinkedList(object):
class _StackNode(object):
def __init__(self, item=None, link=None):
self.item = item
self.link = link
def get_item(self):
return self.item
def get_next(self):
return self.link
def set_next(self, new_next):
self.link = new_next
def __init__(self, head=None):
self.head = head
def insert(self, item):
new_node = Node(item)
new_node.set_next(self.head)
self.head = new_node
def __len__(self):
current = self.head
count = 0
while current:
count += 1
current = current.get_next()
return count
def peek(self):
current_node = self.head
while current_node is not None:
print current_node.item, " -> ",
current_node = current_node.next
print None
def pop(self, node_value):
current_node = self.head
previous_node = None
while current_node is not None:
if current_node.item == node_value:
# if this is the first node (head)
if previous_node is not None:
previous_node.next = current_node.next
else:
self.head = current_node.next
previous_node = current_node
current_node = current_node.next
def push(self, item):
node = Node(item, None)
if self.head is None:
self.head = self.tail = node
else:
self.tail.next = node
self.tail = node
Solution
class LinkedList(object):
class _StackNode(object):
def __init__(self, item=None, link=None):
self.item = item
self.link = link
def get_item(self):
return self.item
def get_next(self):
return self.link
def set_next(self, new_next):
self.link = new_next
def __init__(self, head=None):
self.head = head
def insert(self, item):
new_node = Node(item)
new_node.set_next(self.head)
self.head = new_node
def __len__(self):
current = self.head
count = 0
while current:
count += 1
current = current.get_next()
return count
def peek(self):
current_node = self.head
while current_node is not None:
print current_node.item, " -> ",
current_node = current_node.next
print None
def pop(self, node_value):
current_node = self.head
previous_node = None
while current_node is not None:
if current_node.item == node_value:
# if this is the first node (head)
if previous_node is not None:
previous_node.next = current_node.next
else:
self.head = current_node.next
previous_node = current_node
current_node = current_node.next
def push(self, item):
node = Node(item, None)
if self.head is None:
self.head = self.tail = node
else:
self.tail.next = node
self.tail = node

More Related Content

More from sooryasalini

Polarity is measured on a scale of electronegativ.pdf
                     Polarity is measured on a scale of electronegativ.pdf                     Polarity is measured on a scale of electronegativ.pdf
Polarity is measured on a scale of electronegativ.pdfsooryasalini
 
Geometric isomers are a subset of stereoisomers. .pdf
                     Geometric isomers are a subset of stereoisomers. .pdf                     Geometric isomers are a subset of stereoisomers. .pdf
Geometric isomers are a subset of stereoisomers. .pdfsooryasalini
 
Scientists Contributions Stanley Miller Conducted an experiment .pdf
    Scientists Contributions   Stanley Miller Conducted an experiment .pdf    Scientists Contributions   Stanley Miller Conducted an experiment .pdf
Scientists Contributions Stanley Miller Conducted an experiment .pdfsooryasalini
 
1) Microfinance is the provision of small-scale financial services t.pdf
1) Microfinance is the provision of small-scale financial services t.pdf1) Microfinance is the provision of small-scale financial services t.pdf
1) Microfinance is the provision of small-scale financial services t.pdfsooryasalini
 
The components of individual health are as followsThe three compon.pdf
The components of individual health are as followsThe three compon.pdfThe components of individual health are as followsThe three compon.pdf
The components of individual health are as followsThe three compon.pdfsooryasalini
 
-Lower income households have become more concentrated in U.S. centr.pdf
-Lower income households have become more concentrated in U.S. centr.pdf-Lower income households have become more concentrated in U.S. centr.pdf
-Lower income households have become more concentrated in U.S. centr.pdfsooryasalini
 
NO+ note O has one more electron then N, thus, .pdf
                     NO+  note O has one more electron then N, thus, .pdf                     NO+  note O has one more electron then N, thus, .pdf
NO+ note O has one more electron then N, thus, .pdfsooryasalini
 
Yes, we should be very suspicious of the bones authenticity. This .pdf
Yes, we should be very suspicious of the bones authenticity. This .pdfYes, we should be very suspicious of the bones authenticity. This .pdf
Yes, we should be very suspicious of the bones authenticity. This .pdfsooryasalini
 
WHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdf
WHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdfWHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdf
WHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdfsooryasalini
 
Web 3.0 is just how, why and at what time.Web serviceis a software.pdf
Web 3.0 is just how, why and at what time.Web serviceis a software.pdfWeb 3.0 is just how, why and at what time.Web serviceis a software.pdf
Web 3.0 is just how, why and at what time.Web serviceis a software.pdfsooryasalini
 
There are a few different reagent could be used to perform this tran.pdf
There are a few different reagent could be used to perform this tran.pdfThere are a few different reagent could be used to perform this tran.pdf
There are a few different reagent could be used to perform this tran.pdfsooryasalini
 
now a days security is very important to organization and physical s.pdf
now a days security is very important to organization and physical s.pdfnow a days security is very important to organization and physical s.pdf
now a days security is very important to organization and physical s.pdfsooryasalini
 
5.Write the VHDL code for the state machine.library ieee;use i.pdf
5.Write the VHDL code for the state machine.library ieee;use i.pdf5.Write the VHDL code for the state machine.library ieee;use i.pdf
5.Write the VHDL code for the state machine.library ieee;use i.pdfsooryasalini
 
pH = pKa + log([A-][HA])(base) HONH2 + H2O (acid) HONH3+ + OH-.pdf
pH = pKa + log([A-][HA])(base) HONH2 + H2O  (acid) HONH3+ + OH-.pdfpH = pKa + log([A-][HA])(base) HONH2 + H2O  (acid) HONH3+ + OH-.pdf
pH = pKa + log([A-][HA])(base) HONH2 + H2O (acid) HONH3+ + OH-.pdfsooryasalini
 
Solution Relation between carpels and locules Carpels is the p.pdf
Solution Relation between carpels and locules Carpels is the p.pdfSolution Relation between carpels and locules Carpels is the p.pdf
Solution Relation between carpels and locules Carpels is the p.pdfsooryasalini
 
Solution.Providing legal advice to the president of the company co.pdf
Solution.Providing legal advice to the president of the company co.pdfSolution.Providing legal advice to the president of the company co.pdf
Solution.Providing legal advice to the president of the company co.pdfsooryasalini
 
S and Se are 6th group elementsSize increase the leaving nature in.pdf
S and Se are 6th group elementsSize increase the leaving nature in.pdfS and Se are 6th group elementsSize increase the leaving nature in.pdf
S and Se are 6th group elementsSize increase the leaving nature in.pdfsooryasalini
 
Please refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdfPlease refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdfsooryasalini
 
Simple DefinationsIntertidal zone is the area that is above wate.pdf
Simple DefinationsIntertidal zone  is the area that is above wate.pdfSimple DefinationsIntertidal zone  is the area that is above wate.pdf
Simple DefinationsIntertidal zone is the area that is above wate.pdfsooryasalini
 
Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfsooryasalini
 

More from sooryasalini (20)

Polarity is measured on a scale of electronegativ.pdf
                     Polarity is measured on a scale of electronegativ.pdf                     Polarity is measured on a scale of electronegativ.pdf
Polarity is measured on a scale of electronegativ.pdf
 
Geometric isomers are a subset of stereoisomers. .pdf
                     Geometric isomers are a subset of stereoisomers. .pdf                     Geometric isomers are a subset of stereoisomers. .pdf
Geometric isomers are a subset of stereoisomers. .pdf
 
Scientists Contributions Stanley Miller Conducted an experiment .pdf
    Scientists Contributions   Stanley Miller Conducted an experiment .pdf    Scientists Contributions   Stanley Miller Conducted an experiment .pdf
Scientists Contributions Stanley Miller Conducted an experiment .pdf
 
1) Microfinance is the provision of small-scale financial services t.pdf
1) Microfinance is the provision of small-scale financial services t.pdf1) Microfinance is the provision of small-scale financial services t.pdf
1) Microfinance is the provision of small-scale financial services t.pdf
 
The components of individual health are as followsThe three compon.pdf
The components of individual health are as followsThe three compon.pdfThe components of individual health are as followsThe three compon.pdf
The components of individual health are as followsThe three compon.pdf
 
-Lower income households have become more concentrated in U.S. centr.pdf
-Lower income households have become more concentrated in U.S. centr.pdf-Lower income households have become more concentrated in U.S. centr.pdf
-Lower income households have become more concentrated in U.S. centr.pdf
 
NO+ note O has one more electron then N, thus, .pdf
                     NO+  note O has one more electron then N, thus, .pdf                     NO+  note O has one more electron then N, thus, .pdf
NO+ note O has one more electron then N, thus, .pdf
 
Yes, we should be very suspicious of the bones authenticity. This .pdf
Yes, we should be very suspicious of the bones authenticity. This .pdfYes, we should be very suspicious of the bones authenticity. This .pdf
Yes, we should be very suspicious of the bones authenticity. This .pdf
 
WHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdf
WHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdfWHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdf
WHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdf
 
Web 3.0 is just how, why and at what time.Web serviceis a software.pdf
Web 3.0 is just how, why and at what time.Web serviceis a software.pdfWeb 3.0 is just how, why and at what time.Web serviceis a software.pdf
Web 3.0 is just how, why and at what time.Web serviceis a software.pdf
 
There are a few different reagent could be used to perform this tran.pdf
There are a few different reagent could be used to perform this tran.pdfThere are a few different reagent could be used to perform this tran.pdf
There are a few different reagent could be used to perform this tran.pdf
 
now a days security is very important to organization and physical s.pdf
now a days security is very important to organization and physical s.pdfnow a days security is very important to organization and physical s.pdf
now a days security is very important to organization and physical s.pdf
 
5.Write the VHDL code for the state machine.library ieee;use i.pdf
5.Write the VHDL code for the state machine.library ieee;use i.pdf5.Write the VHDL code for the state machine.library ieee;use i.pdf
5.Write the VHDL code for the state machine.library ieee;use i.pdf
 
pH = pKa + log([A-][HA])(base) HONH2 + H2O (acid) HONH3+ + OH-.pdf
pH = pKa + log([A-][HA])(base) HONH2 + H2O  (acid) HONH3+ + OH-.pdfpH = pKa + log([A-][HA])(base) HONH2 + H2O  (acid) HONH3+ + OH-.pdf
pH = pKa + log([A-][HA])(base) HONH2 + H2O (acid) HONH3+ + OH-.pdf
 
Solution Relation between carpels and locules Carpels is the p.pdf
Solution Relation between carpels and locules Carpels is the p.pdfSolution Relation between carpels and locules Carpels is the p.pdf
Solution Relation between carpels and locules Carpels is the p.pdf
 
Solution.Providing legal advice to the president of the company co.pdf
Solution.Providing legal advice to the president of the company co.pdfSolution.Providing legal advice to the president of the company co.pdf
Solution.Providing legal advice to the president of the company co.pdf
 
S and Se are 6th group elementsSize increase the leaving nature in.pdf
S and Se are 6th group elementsSize increase the leaving nature in.pdfS and Se are 6th group elementsSize increase the leaving nature in.pdf
S and Se are 6th group elementsSize increase the leaving nature in.pdf
 
Please refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdfPlease refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdf
 
Simple DefinationsIntertidal zone is the area that is above wate.pdf
Simple DefinationsIntertidal zone  is the area that is above wate.pdfSimple DefinationsIntertidal zone  is the area that is above wate.pdf
Simple DefinationsIntertidal zone is the area that is above wate.pdf
 
Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdf
 

Recently uploaded

Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 

Recently uploaded (20)

Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 

class LinkedList(object)    class _StackNode(object) .pdf

  • 1. class LinkedList(object): class _StackNode(object): def __init__(self, item=None, link=None): self.item = item self.link = link def get_item(self): return self.item def get_next(self): return self.link def set_next(self, new_next): self.link = new_next def __init__(self, head=None): self.head = head def insert(self, item): new_node = Node(item) new_node.set_next(self.head) self.head = new_node def __len__(self): current = self.head count = 0 while current: count += 1 current = current.get_next() return count
  • 2. def peek(self): current_node = self.head while current_node is not None: print current_node.item, " -> ", current_node = current_node.next print None def pop(self, node_value): current_node = self.head previous_node = None while current_node is not None: if current_node.item == node_value: # if this is the first node (head) if previous_node is not None: previous_node.next = current_node.next else: self.head = current_node.next previous_node = current_node current_node = current_node.next def push(self, item): node = Node(item, None) if self.head is None: self.head = self.tail = node else: self.tail.next = node self.tail = node Solution class LinkedList(object): class _StackNode(object):
  • 3. def __init__(self, item=None, link=None): self.item = item self.link = link def get_item(self): return self.item def get_next(self): return self.link def set_next(self, new_next): self.link = new_next def __init__(self, head=None): self.head = head def insert(self, item): new_node = Node(item) new_node.set_next(self.head) self.head = new_node def __len__(self): current = self.head count = 0 while current: count += 1 current = current.get_next() return count def peek(self): current_node = self.head while current_node is not None: print current_node.item, " -> ", current_node = current_node.next print None
  • 4. def pop(self, node_value): current_node = self.head previous_node = None while current_node is not None: if current_node.item == node_value: # if this is the first node (head) if previous_node is not None: previous_node.next = current_node.next else: self.head = current_node.next previous_node = current_node current_node = current_node.next def push(self, item): node = Node(item, None) if self.head is None: self.head = self.tail = node else: self.tail.next = node self.tail = node