-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.html
More file actions
202 lines (165 loc) · 6.3 KB
/
LinkedList.html
File metadata and controls
202 lines (165 loc) · 6.3 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
<link rel="stylesheet" href="Arrays.css">
<title>Linked List</title>
</head>
<body>
<nav>
<input type="checkbox" id="check">
<label for="check" class="checkbtn">
<i class="fas fa-bars"></i>
</label>
<label class="logo">Codeinfo</label>
<ul>
<li><a class="active" href="index.html">Home</a></li>
<li><a href="Arrays.html">Arrays</a></li>
<li><a href="Stacks.html">Stacks</a></li>
<li><a href="queues.html">Queues</a></li>
<li><a href="LinkedList.html">Linkedlist</a></li>
<li><a href="Heaps.html">Heaps</a></li>
<li><a href="Trees.html">Trees</a></li>
</ul>
</nav>
<div class = "matter">
<h1><strong>Linked Lists</strong></h1> <br>
<p>A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers as shown in the below image:</p>
<img src="Linkedlist.png" alt="">
<h3>Types of Linked Lists</h3> <br>
<p>
1. Single Linked Lists <br>
2. Doubly Linked Lists <br>
3. Circular Linked Lists <br>
</p>
<br>
<h3>Single Linked List</h3> <br>
<p>
<li>A singly linked list is a concrete data structure consisting of a sequence of nodes</li>
<li>Each node has a</li>
<pre>
1. Data part
2. Address part
</pre>
</p>
<br>
<br>
<h3>Implementation</h3> <br>
<h4>Defining a node</h4> <br>
<p>The Node contains 2 parts, one that is the data itself and the other which references the next node in the sequence.</p>
<br>
<p>In C, the node is defined as a structure . This type of a structure is called a self-referential structure where one member of the structure points to the structure of its kind.</p>
<br>
<pre><code>
struct Node{
int data;
struct Node *next;
};
</code></pre>
<br>
<p>A new Node can be created with a desirable variable name</p> <br>
<pre><code>
struct Node* newNode;
</code></pre> <br>
<p>The data part of the node can be accessed using the arrow character</p> <br>
<pre>
<code>
newNode->data
</code>
</pre> <br>
<p>Similarly,the address part can be accessed using the arrow character</p> <br>
<pre><code>
newNode->next
</code></pre> <br>
<h5>Program for the Linked List</h5> <br>
<script src="https://gist.github.com/hrudai2002/e705366e34f22725d26e4aa39ec8f841.js"></script>
<br>
<h3>Doubly Linked List</h3> <br>
<p>Doubly linked list is a type of linked list in which each node apart from storing its data has two links. The first link points to the previous node in the list and the second link points to the next node in the list. </p>
<br>
<p> The first node of the list has its previous link pointing to NULL similarly the last node of the list has its next node pointing to NULL.</p> <br>
<br>
<h3>Implementation</h3> <br>
<h4>Defining a node</h4> <br>
<p>The Node contains 3 parts, one that is the data itself and the other which references the next node in the sequence and the other which refers the previous node.</p>
<br>
<p>In C, the node is defined as a structure . This type of a structure is called a self-referential structure where one member of the structure points to the structure of its kind.</p>
<br>
<pre><code>
struct Node{
int data;
struct Node *prev;
struct Node *next;
};
</code></pre>
<br>
<p>A new Node can be created with a desirable variable name</p> <br>
<pre><code>
struct Node* newNode;
</code></pre> <br>
<p>The data part of the node can be accessed using the arrow character</p> <br>
<pre>
<code>
newNode->data
</code>
</pre> <br>
<p>Similarly,the address of the next node can be accessed using the arrow character</p> <br>
<pre><code>
newNode->next
</code></pre> <br>
<p>Similarly,the address of the previous node can be accessed using the arrow character</p> <br>
<pre><code>
newNode->prev
</code></pre> <br>
<h5>Program for the doubly Linked List</h5> <br>
<script src="https://gist.github.com/hrudai2002/4026648f273fa9d38717f8eba245545a.js"></script> <br>
<h3>Circular Linked List</h3> <br>
<p>A circular linked list is a sequence of elements in which every element has a link to its next element in the sequence and the last element has a link to the first element.</p> <br><p>That means circular linked list is similar to the single linked list except that the last node points to the first node in the list.</p>
<br>
<br>
<h3>Implementation</h3> <br>
<h4>Defining a node</h4> <br>
<p>The Node contains 2 parts, one that is the data itself and the other which references the next node in the sequence.</p>
<br>
<p>In C, the node is defined as a structure . This type of a structure is called a self-referential structure where one member of the structure points to the structure of its kind.</p>
<br>
<pre><code>
struct Node{
int data;
struct Node *next;
};
</code></pre>
<br>
<p>A new Node can be created with a desirable variable name</p> <br>
<pre><code>
struct Node* newNode;
</code></pre> <br>
<p>The data part of the node can be accessed using the arrow character</p> <br>
<pre>
<code>
newNode->data
</code>
</pre> <br>
<p>Similarly,the address of the next node can be accessed using the arrow character</p> <br>
<pre><code>
newNode->next
</code></pre> <br>
<h5>Program for the Circular Linked List</h5> <br>
<script src="https://gist.github.com/hrudai2002/17e9938471257ce0b4fe67f721cb7e6a.js"></script> <br>
<footer>
<div class="footer-content">
<h3>codeinfo</h3>
<p>Learn to code with our beginner-friendly tutorials and examples. Read tutorials, try examples, write programs, and learn to code.</p>
<ul class="socials">
</ul>
</div>
<div class="footer-bottom">
<p>copyright ©2021 codeinfo. designed by <span>nithin</span></p>
</div>
</footer>
</body>
</html>