Skip to content

Commit ecc991a

Browse files
Update 2. Linked List Input & Print.ipynb
1 parent b232860 commit ecc991a

File tree

1 file changed

+36
-77
lines changed

1 file changed

+36
-77
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,36 @@
1-
{
2-
"cells": [
3-
{
4-
"cell_type": "code",
5-
"execution_count": 12,
6-
"metadata": {},
7-
"outputs": [
8-
{
9-
"name": "stdout",
10-
"output_type": "stream",
11-
"text": [
12-
"1 2 3 4 5 -1\n",
13-
"1->2->3->4->5->None\n"
14-
]
15-
}
16-
],
17-
"source": [
18-
"class Node:\n",
19-
" def __init__(self,data):\n",
20-
" self.data = data\n",
21-
" self.next = None\n",
22-
" \n",
23-
"def printLL(head):\n",
24-
" \n",
25-
" while head is not None:\n",
26-
" print(str(head.data) + \"->\",end=\"\")\n",
27-
" head = head.next\n",
28-
" print(\"None\")\n",
29-
" return\n",
30-
" \n",
31-
"def takeInput():\n",
32-
" \n",
33-
" inputList = [int(ele) for ele in input().split()]\n",
34-
" head = None\n",
35-
" for currData in inputList:\n",
36-
" if currData == -1:\n",
37-
" break\n",
38-
" \n",
39-
" newNode = Node(currData)\n",
40-
" if head is None:\n",
41-
" head = newNode\n",
42-
" \n",
43-
" else:\n",
44-
" curr = head\n",
45-
" while curr.next is not None:\n",
46-
" curr = curr.next\n",
47-
" curr.next = newNode\n",
48-
" \n",
49-
" return head\n",
50-
"\n",
51-
"head = takeInput()\n",
52-
"printLL(head)"
53-
]
54-
}
55-
],
56-
"metadata": {
57-
"kernelspec": {
58-
"display_name": "Python 3",
59-
"language": "python",
60-
"name": "python3"
61-
},
62-
"language_info": {
63-
"codemirror_mode": {
64-
"name": "ipython",
65-
"version": 3
66-
},
67-
"file_extension": ".py",
68-
"mimetype": "text/x-python",
69-
"name": "python",
70-
"nbconvert_exporter": "python",
71-
"pygments_lexer": "ipython3",
72-
"version": "3.8.5"
73-
}
74-
},
75-
"nbformat": 4,
76-
"nbformat_minor": 4
77-
}
1+
class Node:
2+
def __init__(self,data):
3+
self.data = data
4+
self.next = None
5+
6+
def printLL(head):
7+
8+
while head is not None:
9+
print(str(head.data) + "->",end="")
10+
head = head.next
11+
print("None")
12+
return
13+
14+
def takeInput():
15+
16+
inputList = [int(ele) for ele in input().split()]
17+
head = None
18+
for currData in inputList:
19+
if currData == -1:
20+
break
21+
22+
newNode = Node(currData)
23+
if head is None:
24+
head = newNode
25+
26+
else:
27+
curr = head
28+
while curr.next!=None:
29+
curr = curr.next
30+
curr.next = newNode
31+
32+
return head
33+
34+
head = takeInput()
35+
print(head)
36+
printLL(head)

0 commit comments

Comments
 (0)