-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
linkedlist.html
520 lines (458 loc) · 23.4 KB
/
linkedlist.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
<!DOCTYPE html>
<html lang="en">
<head>
<title>eduAlgo - LinkedList</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="A very simple python package made with python scripts to study different algorithms for educational purposes.">
<meta name="author" content="Abhijit2505">
<meta property="og:image" content="assets/images/eduAlgo-doc.png" />
<link rel="shortcut icon" href="favicon.ico">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/css2?family=Recursive&family=Zilla+Slab:wght@300&display=swap" rel="stylesheet">
<script defer src="assets/fontawesome/js/all.js"></script>
<link rel="stylesheet" href="assets/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/plugins/prism/prism.css">
<link rel="stylesheet" href="assets/plugins/elegant_font/css/style.css">
<link id="theme-style" rel="stylesheet" href="assets/css/styles.css">
</head>
<body class="body-green">
<div class="page-wrapper">
<header id="header" class="header">
<div class="container">
<div class="branding">
<h1 class="logo">
<a href="index.html">
<span class="text-highlight">edu </span><span class="text-bold">Algo</span>
</a>
</h1>
</div>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.html">Home</a></li>
<li class="breadcrumb-item"><a href="start.html">Documentation</a></li>
<li class="breadcrumb-item active">
LinkedList
</li>
</ol>
<div class="top-search-box">
<form class="form-inline search-form justify-content-center" action="" method="get">
<input type="text" placeholder="Search..." name="search" class="form-control search-input">
<button type="submit" class="btn search-btn" value="Search"><i class="fas fa-search"></i></button>
</form>
</div>
</div>
</header>
<div class="doc-wrapper">
<div class="container">
<div id="doc-header" class="doc-header text-center">
<h1 class="doc-title"><i class="icon fas fa-file-contract"></i> Linked List Implementations</h1>
<div class="meta"><i class="far fa-clock"></i> Last updated: 19th Aug, 2020</div>
</div>
<div class="doc-body row">
<div class="doc-content col-md-9 col-12 order-1">
<div class="content-inner">
<section id="code-section" class="doc-section">
<h2 class="section-title">Linked List Module</h2>
<p>
The <b>LinkedList</b> module of the eduAlgo package contains ten classic LinkedList algorithms,
<ul>
<li>
Palindromic Linked List - <img src="https://img.shields.io/badge/-implemented-green"></li>
<li>Remove Linked List Elements - <img src="https://img.shields.io/badge/-implemented-green"></li>
<li>Remove Duplicates From a Sorted List - <img src="https://img.shields.io/badge/-implemented-green"></li>
<li>Merge Two Sorted List - <img src="https://img.shields.io/badge/-implemented-green"></li>
<li>Reverse Linked List - <img src="https://img.shields.io/badge/-implemented-green"></li>
<li>Delete Node In a Linked List - <img src="https://img.shields.io/badge/-implemented-green"></li>
<li>Middle Of the Linked List - <img src="https://img.shields.io/badge/-implemented-green"> </li>
<li>Length of the Linked List - <img src="https://img.shields.io/badge/-implemented-green"></li>
<li>Getting Decimal Value from Binary - <img src="https://img.shields.io/badge/-implemented-green"></li>
<li>Next Larger Nodes - <img src="https://img.shields.io/badge/-implemented-green"></li>
</ul>
</p>
<div id="palindromic" class="section-block">
<h5><u>Palindromic Linked List</u></h5>
<p>
<b>Module:</b> list_algorithms()<br />
<b>Method :</b> <i>is_palindrome(head), is_palindrome_optimized(head)</i><br />
<b>Uses :</b> To check if a Linked List is palindromic or not. "is_palindrome_optimized()" is the optimized version of
the same using another algorithmic approach unlike the normal one which uses <b>stack</b>.<br />
<b>Parameters :</b> head - head node of the Linked List, this method returs a <b>boolean</b> variable.
</p>
<div class="code-block">
<div id="python" class="section-block">
<div class="code-block">
<h6>Python Code Example</h6>
<pre><code class="language-python">from edualgo import LinkedList as ll
llist1 = ll.linkedlist()
arr1 = list(map(int,input().split()))
for i in arr1:
llist1.append(i)
sol = ll.list_algorithms()
print(sol.is_palindrome(llist1.head))</code></pre>
<pre><code class="language-python">Input:
1 2 2 2 1
Output:
True</code>
</pre>
</div>
</div>
</div>
</div>
<div id="remove-elements" class="section-block">
<h5><u>Remove Linked List Elements</u></h5>
<p>
<b>Module:</b> list_algorithms()<br />
<b>Method :</b> <i>removeElements(head,val)</i><br />
<b>Uses :</b> To remove all the occurance of a specific element passed as an arguement "val".<br />
<b>Parameters :</b> head - head node of the Linked List, val - value to remove all the occurances. This method returns a <b>Linked List node obejct</b>.
</p>
<div class="code-block">
<div id="python" class="section-block">
<div class="code-block">
<h6>Python Code Example</h6>
<pre><code class="language-python">from edualgo import LinkedList as ll
llist1 = ll.linkedlist()
arr1 = list(map(int,input().split()))
for i in arr1:
llist1.append(i)
num = int(input())
sol = ll.list_algorithms()
llist3 = ll.linkedlist()
llist3.head = sol.removeElements(llist1.head,num)
llist3.printLL()</code></pre>
<pre><code class="language-python">Input:
1 2 3 4 5 6 6 2 2 4 9
6
Output:
1 2 3 4 5 2 2 4 9 </code>
</pre>
</div>
</div>
</div>
</div>
<div id="remove-duplicates" class="section-block">
<h5><u>Remove Duplicates From a Sorted List</u></h5>
<p>
<b>Module:</b> list_algorithms()<br />
<b>Method :</b> <i>delete_sorted_duplicates(head)</i><br />
<b>Uses :</b> To remove all the duplicate occurance from a sorted Linked List<br />
<b>Parameters :</b> head - head node of the Linked List. This method returns a <b>Linked List node obejct</b>.
</p>
<div class="code-block">
<div id="python" class="section-block">
<div class="code-block">
<h6>Python Code Example</h6>
<pre><code class="language-python">from edualgo import LinkedList as ll
llist1 = ll.linkedlist()
arr1 = list(map(int,input().split()))
for i in arr1:
llist1.append(i)
sol = ll.list_algorithms()
llist3 = ll.linkedlist()
llist3.head = sol.delete_sorted_duplicate(llist1.head)
llist3.printLL()</code></pre>
<pre><code class="language-python">Input:
1 2 2 3 3 5 5 9 9
Output:
1 2 3 5 9 </code>
</pre>
</div>
</div>
</div>
</div>
<div id="merge-lists" class="section-block">
<h5><u>Merge Two Sorted Lists</u></h5>
<p>
<b>Module:</b> list_algorithms()<br />
<b>Method :</b> <i> mergeTwoLists(head1,head2)</i><br />
<b>Uses :</b> To merge two Linked Lists.<br />
<b>Parameters :</b> head1 - head node of the first
Linked List. head2 - head node of the second Linked List.
This method returns the head of the merged linked list as a <b>Linked List node obejct</b>.
</p>
<div class="code-block">
<div id="python" class="section-block">
<div class="code-block">
<h6>Python Code Example</h6>
<pre><code class="language-python">from edualgo import LinkedList as ll
llist1 = ll.linkedlist()
llist2 = ll.linkedlist()
arr1 = list(map(int,input().split()))
arr2 = list(map(int,input().split()))
for i in arr1:
llist1.append(i)
for i in arr2:
llist2.append(i)
sol = ll.list_algorithms()
llist3 = ll.linkedlist()
llist3.head = sol.mergeTwoLists(llist1.head,llist2.head)
llist3.printLL()</code></pre>
<pre><code class="language-python">Input:
1 2 3 2 1
4 5 6 8 9
Output:
1 2 3 2 1 4 5 6 8 9 </code>
</pre>
</div>
</div>
</div>
</div>
<div id="reversee-lists" class="section-block">
<h5><u>Reverse Linked Lists</u></h5>
<p>
<b>Module:</b> list_algorithms()<br />
<b>Method :</b> <i>reverse_linked_recursive(head),<br />
reverse_linked_iterative(head)</i><br />
<b>Uses :</b> To reverse a Linked Lists (recursive and iterative approach).<br />
<b>Parameters :</b> head- head node of the first
Linked List. This method returns the head of the reversed linked list as a <b>Linked List node obejct</b>.
</p>
<div class="code-block">
<div id="python" class="section-block">
<div class="code-block">
<h6>Python Code Example</h6>
<pre><code class="language-python">from edualgo import LinkedList as ll
llist1 = ll.linkedlist()
arr1 = list(map(int,input().split()))
for i in arr1:
llist1.append(i)
sol = ll.list_algorithms()
llist3 = ll.linkedlist()
llist3.head = sol.reverse_linked_iterative(llist1.head)
llist3.printLL()</code></pre>
<pre><code class="language-python">Input:
1 2 3 4 5
Output:
5 4 3 2 1 </code>
</pre>
</div>
</div>
</div>
</div>
<div id="delete-node-lists" class="section-block">
<h5><u>Delete Node In a Linked Lists</u></h5>
<p>
<b>Module:</b> list_algorithms()<br />
<b>Method :</b> <i>delete_node(head)</i><br />
<b>Uses :</b> To delete a particular given node passed as a reference.<br />
<b>Parameters :</b> head- head node of the first
Linked List. This method returns <b>void</b>.
</p>
<div class="code-block">
<div id="python" class="section-block">
<div class="code-block">
<h6>Python Code Example</h6>
<pre><code class="language-python">from edualgo import LinkedList as ll
llist1 = ll.linkedlist()
arr1 = list(map(int,input().split()))
for i in arr1:
llist1.append(i)
sol = ll.list_algorithms()
sol.delete_node(llist1.head)
llist1.printLL()</code></pre>
<pre><code class="language-python">Input:
1 2 3 4 5 6
Output:
2 3 4 5 6 </code>
</pre>
</div>
</div>
</div>
</div>
<div id="middle-lists" class="section-block">
<h5><u>Middle of the Linked Lists</u></h5>
<p>
<b>Module:</b> list_algorithms()<br />
<b>Method :</b> <i> middleNode(head)</i><br />
<b>Uses :</b> To get the middle node of a Linked List.<br />
<b>Parameters :</b> head- head node of the first
Linked List. This method returns the middle node as a <b>Linked List Object</b>.
</p>
<div class="code-block">
<div id="python" class="section-block">
<div class="code-block">
<h6>Python Code Example</h6>
<pre><code class="language-python">from edualgo import LinkedList as ll
llist1 = ll.linkedlist()
arr1 = list(map(int,input().split()))
for i in arr1:
llist1.append(i)
sol = ll.list_algorithms()
print(sol.middleNode(llist1.head).data)</code></pre>
<pre><code class="language-python">Input:
1 2 3 4 5 6
Output:
4 </code>
</pre>
</div>
</div>
</div>
</div>
<div id="length-lists" class="section-block">
<h5><u>Length Of the Linked List</u></h5>
<p>
<b>Module:</b> list_algorithms()<br />
<b>Method :</b> <i> length(head)</i><br />
<b>Uses :</b> To get the length of a Linked List.<br />
<b>Parameters :</b> head- head node of the first
Linked List. This method returns the length of the Linked List as an <b>integer</b>.
</p>
<div class="code-block">
<div id="python" class="section-block">
<div class="code-block">
<h6>Python Code Example</h6>
<pre><code class="language-python">from edualgo import LinkedList as ll
llist1 = ll.linkedlist()
arr1 = list(map(int,input().split()))
for i in arr1:
llist1.append(i)
sol = ll.list_algorithms()
print(sol.length(llist1.head))</code></pre>
<pre><code class="language-python">Input:
1 2 3 4 5 6
Output:
6 </code>
</pre>
</div>
</div>
</div>
</div>
<div id="decimal" class="section-block">
<h5><u>Getting Decimal Value From Binary</u></h5>
<p>
<b>Module:</b> list_algorithms()<br />
<b>Method :</b> <i>getDecimalValue(head)</i><br />
<b>Uses :</b> To get the decimal value of a Binary Linked List<br />
<b>Parameters :</b> head- head node of the
Linked List. This method returns the decimal of the Linked List as an <b>integer</b>.
</p>
<div class="code-block">
<div id="python" class="section-block">
<div class="code-block">
<h6>Python Code Example</h6>
<pre><code class="language-python">from edualgo import LinkedList as ll
llist1 = ll.linkedlist()
arr1 = list(map(int,input().split()))
for i in arr1:
llist1.append(i)
sol = ll.list_algorithms()
print(sol.getDecimalValue(llist1.head))</code></pre>
<pre><code class="language-python">Input:
1 0 0 1 0 1
Output:
37 </code>
</pre>
</div>
</div>
</div>
</div>
<div id="next-greater" class="section-block">
<h5><u>Next Larger Nodes</u></h5>
<p>
<b>Module:</b> list_algorithms()<br />
<b>Method :</b> <i>nextLargerNodes(head)</i><br />
<b>Uses :</b> To get the just greated node of the Linked List elements<br />
<b>Parameters :</b> head- head node of the
Linked List. This method returns a <b>list</b> having the
same size as that of the Linked List where the list holds the next
larger node for each Linked List elements.
</p>
<div class="code-block">
<div id="python" class="section-block">
<div class="code-block">
<h6>Python Code Example</h6>
<pre><code class="language-python">from edualgo import LinkedList as ll
llist1 = ll.linkedlist()
arr1 = list(map(int,input().split()))
for i in arr1:
llist1.append(i)
sol = ll.list_algorithms()
print(sol.nextLargerNodes(llist1.head))</code></pre>
<pre><code class="language-python">Input:
2 1 5
Output:
[5,5,0] </code>
</pre>
</div>
</div>
</div>
</div>
</section>
<div id="doc-header" class="doc-header text-center">
<h1 class="doc-title"><i class="icon fas fa-bug"></i> Found Some Bugs ?</h1>
<div class="meta"><i class="far fa-envelope"></i> Mail The Developer here - [email protected]</div>
</div>
</div>
</div>
<div class="doc-sidebar col-md-3 col-12 order-0 d-none d-md-flex">
<div id="doc-nav" class="doc-nav">
<nav id="doc-menu" class="nav doc-menu flex-column sticky">
<a class="nav-link scrollto" href="#code-section">Linked List Implementations</a>
<nav class="doc-sub-menu nav flex-column">
<a class="nav-link scrollto" href="#palindromic">Palindromic Linked List</a>
<a class="nav-link scrollto" href="#remove-elements">Remove Linked List Elements</a>
<a class="nav-link scrollto" href="#remove-duplicates">Remove Duplicates From a Sorted List</a>
<a class="nav-link scrollto" href="#merge-lists">Merge Two Sorted List</a>
<a class="nav-link scrollto" href="#reversee-lists">Reverse Linked List</a>
<a class="nav-link scrollto" href="#delete-node-lists">Delete Node In a Linked List</a>
<a class="nav-link scrollto" href="#middle-lists">Middle Of the Linked List</a>
<a class="nav-link scrollto" href="#length-lists">Length of the Linked List</a>
<a class="nav-link scrollto" href="#decimal">Getting Decimal Value From Binary</a>
<a class="nav-link scrollto" href="#next-greater">Next Larger Nodes</a>
</nav>
</nav>
</div>
</div>
</div>
</div>
</div>
<div id="promo-block" class="promo-block">
<div class="container">
<div class="promo-block-inner">
<h3 class="promo-title text-center"><i class="fas fa-code"></i> <a href="#">Are you an ambitious Python Developer ?</a></h3>
<div class="row">
<div class="figure-holder col-lg-5 col-md-6 col-12">
<div class="figure-holder-inner">
<a href="https://github.com/Abhijit2505/eduAlgo" target="_blank"><img class="img-fluid" src="assets/images/eduAlgogithub.PNG" alt="Instance Theme" /></a>
<a class="mask" href="https://github.com/Abhijit2505/eduAlgo" target="_blank"><i class="icon fas fa-star pink"></i></a>
</div>
</div>
<div class="content-holder col-lg-7 col-md-6 col-12">
<div class="content-holder-inner">
<div class="desc">
<p>
Do you want to contribute to our project ? We welcome every python lover to
come forwards and have some fun with our source code.
Steps to contibute:
<ul>
<li>
Send an email to the developer <a href ="mailto:[email protected]">here</a> regarding your willingness to contribute
to the project.
</li>
<li>
Have a read of our "How To Contribute" documentation <a href = "https://github.com/Abhijit2505/eduAlgo/blob/master/CONTRIBUTING.md">here</a>.
</li>
</ul>
Keep coding, keep loving python <i class="fab fa-python"></i>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<footer class="footer text-center">
Copyright 2020 @<a href="https://github.com/Abhijit2505" target="_blank">Abhijit Tripathy</a>. Package Designed by <a href="https://github.com/Abhijit2505" target="_blank">Abhijit Tripathy</a> for python enthusiasts
[Theme Designed by <a href="https://themes.3rdwavemedia.com/" target="_blank">Xiaoying Riley</a>]
</footer>
<script type="text/javascript" src="assets/plugins/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/plugins/prism/prism.js"></script>
<script type="text/javascript" src="assets/plugins/jquery-scrollTo/jquery.scrollTo.min.js"></script>
<script type="text/javascript" src="assets/plugins/stickyfill/dist/stickyfill.min.js"></script>
<script type="text/javascript" src="assets/js/main.js"></script>
</body>
</html>