Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Lecture Demos
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Daniel Moix
Lecture Demos
Commits
dc66ea61
Commit
dc66ea61
authored
1 year ago
by
Daniel Moix
Browse files
Options
Downloads
Patches
Plain Diff
Adding files for Week 8 lecture
parent
8180026b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cs172/Lect07/hello.py
+0
-0
0 additions, 0 deletions
cs172/Lect07/hello.py
cs172/Lect07/linkedlist.py
+51
-0
51 additions, 0 deletions
cs172/Lect07/linkedlist.py
cs172/Lect07/node.py
+31
-0
31 additions, 0 deletions
cs172/Lect07/node.py
with
82 additions
and
0 deletions
cs172/Lect07/hello.py
0 → 100644
+
0
−
0
View file @
dc66ea61
This diff is collapsed.
Click to expand it.
cs172/Lect07/linkedlist.py
0 → 100644
+
51
−
0
View file @
dc66ea61
from
node
import
Node
class
LinkedList
:
def
__init__
(
self
):
self
.
__head
=
None
self
.
__tail
=
None
def
isEmpty
(
self
):
return
self
.
__head
is
None
def
append
(
self
,
value
):
if
self
.
isEmpty
():
self
.
__head
=
Node
(
value
)
self
.
__tail
=
self
.
__head
else
:
self
.
__tail
.
setNext
(
Node
(
value
))
self
.
__tail
=
self
.
__tail
.
getNext
()
def
__str__
(
self
):
#return str(self.__head)
myStr
=
''
current
=
self
.
__head
while
current
is
not
None
:
myStr
+=
str
(
current
.
getData
())
+
"
-->
"
current
=
current
.
getNext
()
myStr
+=
'
🛑
'
return
myStr
def
__len__
(
self
):
if
self
.
isEmpty
():
return
0
else
:
count
=
1
# Traverse
here
=
self
.
__head
while
here
.
getNext
()
is
not
None
:
here
=
here
.
getNext
()
count
+=
1
return
count
if
__name__
==
"
__main__
"
:
myList
=
LinkedList
()
print
(
myList
.
isEmpty
())
print
(
len
(
myList
))
myList
.
append
(
"
A
"
)
print
(
len
(
myList
))
myList
.
append
(
"
B
"
)
myList
.
append
(
"
C
"
)
print
(
myList
.
isEmpty
())
print
(
myList
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
cs172/Lect07/node.py
0 → 100644
+
31
−
0
View file @
dc66ea61
class
Node
:
def
__init__
(
self
,
data
,
next
=
None
):
self
.
__data
=
data
self
.
__next
=
next
def
getData
(
self
):
return
self
.
__data
def
getNext
(
self
):
return
self
.
__next
def
setNext
(
self
,
next
):
self
.
__next
=
next
def
__str__
(
self
):
return
"
A node containing
"
+
str
(
self
.
getData
())
+
\
"
whose next is
"
+
str
(
self
.
getNext
())
if
__name__
==
"
__main__
"
:
myNode
=
Node
(
"
A
"
)
print
(
myNode
.
getData
())
print
(
myNode
.
getNext
())
print
(
myNode
)
yourNode
=
Node
(
"
Z
"
,
myNode
)
print
(
yourNode
)
#print(yourNode.getNext().getData())
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment