1+ {
2+ "nbformat" : 4 ,
3+ "nbformat_minor" : 0 ,
4+ "metadata" : {
5+ "colab" : {
6+ "private_outputs" : true ,
7+ "provenance" : [],
8+ "authorship_tag" : " ABX9TyNc3xjOWrkKTALcqYnVi+z2" ,
9+ "include_colab_link" : true
10+ },
11+ "kernelspec" : {
12+ "name" : " python3" ,
13+ "display_name" : " Python 3"
14+ },
15+ "language_info" : {
16+ "name" : " python"
17+ }
18+ },
19+ "cells" : [
20+ {
21+ "cell_type" : " markdown" ,
22+ "metadata" : {
23+ "id" : " view-in-github" ,
24+ "colab_type" : " text"
25+ },
26+ "source" : [
27+ " <a href=\" https://colab.research.google.com/github/syedabdullahbukhari77/DataStructuresAlgorithmPy/blob/main/B1_Linked_List.ipynb\" target=\" _parent\" ><img src=\" https://colab.research.google.com/assets/colab-badge.svg\" alt=\" Open In Colab\" /></a>"
28+ ]
29+ },
30+ {
31+ "cell_type" : " code" ,
32+ "execution_count" : null ,
33+ "metadata" : {
34+ "id" : " NHLw82ibEcqm"
35+ },
36+ "outputs" : [],
37+ "source" : [
38+ " class Node:\n " ,
39+ " def __init__(self, value):\n " ,
40+ " self.value = value\n " ,
41+ " self.next = None\n "
42+ ]
43+ },
44+ {
45+ "cell_type" : " code" ,
46+ "source" : [
47+ " a = Node(1)\n " ,
48+ " b = Node(1)\n " ,
49+ " c = Node(1)"
50+ ],
51+ "metadata" : {
52+ "id" : " eIfcvH2aB9_l"
53+ },
54+ "execution_count" : null ,
55+ "outputs" : []
56+ },
57+ {
58+ "cell_type" : " code" ,
59+ "source" : [
60+ " print(a.value)"
61+ ],
62+ "metadata" : {
63+ "id" : " olcL6j8DCA7E"
64+ },
65+ "execution_count" : null ,
66+ "outputs" : []
67+ },
68+ {
69+ "cell_type" : " code" ,
70+ "source" : [
71+ " print(c)"
72+ ],
73+ "metadata" : {
74+ "id" : " XKyZYOkaCJ0j"
75+ },
76+ "execution_count" : null ,
77+ "outputs" : []
78+ },
79+ {
80+ "cell_type" : " code" ,
81+ "source" : [
82+ " print(c.value)\n " ,
83+ " print(b.value)"
84+ ],
85+ "metadata" : {
86+ "id" : " tccMOhmECm6A"
87+ },
88+ "execution_count" : null ,
89+ "outputs" : []
90+ },
91+ {
92+ "cell_type" : " code" ,
93+ "source" : [
94+ " id(a)"
95+ ],
96+ "metadata" : {
97+ "id" : " 1FPIc0hpCoxf"
98+ },
99+ "execution_count" : null ,
100+ "outputs" : []
101+ },
102+ {
103+ "cell_type" : " code" ,
104+ "source" : [
105+ " id(b)"
106+ ],
107+ "metadata" : {
108+ "id" : " ONvCoqojCqdW"
109+ },
110+ "execution_count" : null ,
111+ "outputs" : []
112+ },
113+ {
114+ "cell_type" : " code" ,
115+ "source" : [
116+ " id(c)"
117+ ],
118+ "metadata" : {
119+ "id" : " 358h16YsDJpw"
120+ },
121+ "execution_count" : null ,
122+ "outputs" : []
123+ },
124+ {
125+ "cell_type" : " code" ,
126+ "source" : [
127+ " class Node:\n " ,
128+ " def __init__(self, value):\n " ,
129+ " self.value = value\n " ,
130+ " self.next = None\n "
131+ ],
132+ "metadata" : {
133+ "id" : " DI4xVZmYDKWv"
134+ },
135+ "execution_count" : null ,
136+ "outputs" : []
137+ },
138+ {
139+ "cell_type" : " code" ,
140+ "source" : [
141+ " class LinkedList:\n " ,
142+ " def __init__(self):\n " ,
143+ " self.head = None\n " ,
144+ " self.n = 0\n " ,
145+ " \n " ,
146+ " def __len__(self):\n " ,
147+ " return self.n\n " ,
148+ " \n " ,
149+ " def insert_head(self, value):\n " ,
150+ " new_node = Node(value)\n " ,
151+ " \n " ,
152+ " new_node.next = self.head\n " ,
153+ " \n " ,
154+ " self.head = new_node\n " ,
155+ " \n " ,
156+ " self.n = self.n + 1"
157+ ],
158+ "metadata" : {
159+ "id" : " LX81royUESIR"
160+ },
161+ "execution_count" : null ,
162+ "outputs" : []
163+ },
164+ {
165+ "cell_type" : " code" ,
166+ "source" : [
167+ " L = LinkedList()"
168+ ],
169+ "metadata" : {
170+ "id" : " p5WtY3d9ErMG"
171+ },
172+ "execution_count" : null ,
173+ "outputs" : []
174+ },
175+ {
176+ "cell_type" : " code" ,
177+ "source" : [
178+ " L.insert_head(1)\n " ,
179+ " L.insert_head(2)\n " ,
180+ " L.insert_head(3)\n " ,
181+ " L.insert_head(4)"
182+ ],
183+ "metadata" : {
184+ "id" : " Vvdltz7WEtb3"
185+ },
186+ "execution_count" : null ,
187+ "outputs" : []
188+ },
189+ {
190+ "cell_type" : " code" ,
191+ "source" : [
192+ " len(L)"
193+ ],
194+ "metadata" : {
195+ "id" : " ol9L1VjDEu87"
196+ },
197+ "execution_count" : null ,
198+ "outputs" : []
199+ }
200+ ]
201+ }
0 commit comments