SlideShare a Scribd company logo
1 of 64
ARRAYS AND LINKED LIST
Data Structure
Arrays Intro
• Do you listen to music on your smartphone?
• Do you keep a list of contacts on your phone?
• If your answer is “yes” to any of these questions, then it’s almost
certain that you’ve used arrays and you didn’t even know it! ?
• Arrays are very powerful data structures that store lists of elements.
• They have endless applications. They are very important in the world
of computer science.
• To understand how they work, it’s very helpful to visualize your
computer’s memory as a grid, just like the one below. Each piece of
information is stored in one of those small elements (squares) that
make the grid.
Grid structure
Arrays
• Whenever we want to work with large number of data values, we
need to use that much number of different variables.
• As the number of variables are increasing, complexity of the program
also increases and programmers get confused with the variable
names.
• There may be situations in which we need to work with large number
of similar data values.
• To make this work more easy, C or any programming language
provides a concept called "Array".
Arrays
• An array is a variable which can store multiple values of same data
type at a time.
• An array can also be defined as follows...
• "Collection of similar data items stored in continuous memory locations
with single name".
• Arrays are classified as Homogeneous Data Structures because
they store elements of the same type.
• They can store numbers, strings, Boolean values (true and false),
characters, objects, and so on.
• But once you define the type of values that your array will store, all
its elements must be of that same type. You can’t “mix” different
types of data.
When you create an array, you:
• - Assign it to a variable. ?
- Define the type of elements that it will store. ?
- Define its size (the maximum number of elements). ?
• Int myArray [5];
• But how can you tell the computer which particular value you would
like to access? This is where indices take a vital role!
Indices
• You use what it’s called an “index” (“indices” in plural) to access a
value in an array. This is a number that refers to the location where
the value is stored.
• As you can see in the diagram below, the first element in the array is
referred to using index 0. As you move further to the right, the index
increases by one for each space in memory.
The general syntax to access an element is:
<ArrayVariable>[index>]
• For example:
• If your array is stored in the variable myArray and you want to access
the first element (at index 0), you would use myArray[0]
Memory
• Now that you know how to access values, let’s see how
arrays are stored in your computer’s memory. When you
define the size of the array, all of that space in memory is
“reserved” from that moment on for future values that you
may want to insert.
• Note: If you do not fill the array with values, that space will
be kept reserved and empty until you do.
• For Example:
Let’s say that you define an array of size 5 but only insert one
value. All that remaining space will be empty and “reserved”
in memory, waiting for future assignments.
Operations on Array: Insertion
• Let’s say that we have an array of size 6 and there’s still an empty
space.
• We want to insert an element “e” at the beginning of the array (index
0), but this place is already taken by the element “a”
• What should we do?
•
• Note: You will need to create a variable to keep track of the last index
that contains elements. In the diagram above, the array is filled up to
index 4 before the insertion. This way, you can determine if the array
is full and what index you should use to insert an element at the end.
• After doing this, our element is successfully inserted. ?
Wait a minute! What Happens if the Array is
Full?
• In this case, you need to create a new, larger array and manually
copy all the elements into this new array. This operation is very
expensive, time-wise. Imagine what would happen if you had an
array with millions of elements! That could take a very long time to
complete.
Deletion operation of Array
• Now let’s say that you want to delete an element from the array.
•
• To maintain the efficiency of random access (being able to access the
array through an index extremely fast) the elements must be stored in
contiguous spaces of memory.
• You can’t just delete the element and leave that space empty.
• You should move the elements that come after the element that you
want to delete one index the left.
• And finally, you have this resulting array ?. As you can see, “b” has
been successfully deleted.
•
•
Finding an Element
• You have three options to find an element in an array:
• If you know where it’s located, use the index.
• If you don’t know where it’s located and your data is sorted, you can
use algorithms to optimize your search, such as Binary Search.
• If you don’t know where it’s located and your data is not sorted, you
will need to search through every element in the array and check if
the current element is the element you are looking for
Linked List
• When we want to work with unknown number of data values, we
use a linked list data structure to organize that data.
• Linked list is a linear data structure that contains sequence of
elements such that each element links to its next element in the
sequence.
• Each element in a linked list is called as "Node".
• Types: single, double and circular linked lists
What is Single Linked List?
• Simply a list is a sequence of data, and linked list is a sequence of data
linked with each other.
• Single linked list is a sequence of elements in which every element
has link to its next element in the sequence.
• In any single linked list, the individual element is called as "Node".
• Every "Node" contains two fields, data and next.
• The data field is used to store actual value of that node and next field
is used to store the address of the next node in the sequence.
Single Linked List
• The graphical representation of a node in a single linked list is as follows...
• In a single linked list, the address of the first node is always stored in a
reference node known as "front" (Some times it is also known as "head").
• Always next part (reference part) of the last node must be NULL.
Single Linked List
• Example
Operations - Single Linked List
•In a single linked list we perform the
following operations...
•Insertion
•Deletion
•Display
Perform the following steps before
implementing actual operations
• Before we implement actual operations, first we need to setup empty
list. First perform the following steps before implementing actual
operations.
• Step 1: Include all the header files which are used in the program.
• Step 2: Declare all the user defined functions.
• Step 3: Define a Node structure with two members data and next
• Step 4: Define a Node pointer 'head' and set it to NULL.
• Step 4: Implement the main method by displaying operations menu
and make suitable function calls in the main method to perform user
selected operation.
Insertion - Single Linked List
•In a single linked list, the insertion operation can
be performed in three ways. They are as
follows...
•Inserting At Beginning of the list
•Inserting At End of the list
•Inserting At Specific location in the list
Inserting At Beginning of the list
•We can use the following steps to insert a new node
at beginning of the single linked list...
•Step 1: Create a newNode with given value.
•Step 2: Check whether list is Empty (head == NULL)
•Step 3: If it is Empty then,
set newNode→next = NULL and head = newNode.
•Step 4: If it is Not Empty then,
set newNode→next = head and head = newNode.
Inserting At End of the list
• We can use the following steps to insert a new node at end
of the single linked list...
• Step 1: Create a newNode with given value and newNode →
next as NULL.
• Step 2: Check whether list is Empty (head == NULL).
• Step 3: If it is Empty then, set head = newNode.
• Step 4: If it is Not Empty then, define a node
pointer temp and initialize with head.
• Step 5: Keep moving the temp to its next node until it
reaches to the last node in the list (until temp → next is
equal to NULL).
• Step 6: Set temp → next = newNode.
Inserting At Specific location in the list (After a
Node)
• We can use the following steps to insert a new node after a node in the single
linked list...
• Step 1: Create a newNode with given value.
• Step 2: Check whether list is Empty (head == NULL)
• Step 3: If it is Empty then, set newNode → next = NULL and head = newNode.
• Step 4: If it is Not Empty then, define a node pointer temp and initialize
with head.
• Step 5: Keep moving the temp to its next node until it reaches to the node after
which we want to insert the newNode (until temp1 → data is equal to location,
here location is the node value after which we want to insert the newNode).
• Step 6: Every time check whether temp is reached to last node or not. If it is
reached to last node then display 'Given node is not found in the list!!! Insertion
not possible!!!' and terminate the function. Otherwise move the temp to next
node.
• Step 7: Finally, Set 'newNode → next = temp → next' and 'temp →
next = newNode'
Deletion - Single Linked List
• In a single linked list, the deletion operation can be
performed in three ways. They are as follows...
• Deleting from Beginning of the list
• Deleting from End of the list
• Deleting a Specific Node
Deleting from Beginning of the list
• We can use the following steps to delete a node from beginning of
the single linked list...
• Step 1: Check whether list is Empty (head == NULL)
• Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not
possible' and terminate the function.
• Step 3: If it is Not Empty then, define a Node pointer 'temp' and
initialize with head.
• Step 4: Check whether list is having only one node (temp →
next == NULL)
• Step 5: If it is TRUE then set head = NULL and
delete temp (Setting Empty list conditions)
• Step 6: If it is FALSE then set head = temp → next, and delete temp.
Deleting from End of the list
• We can use the following steps to delete a node from end of the single
linked list...
• Step 1: Check whether list is Empty (head == NULL)
• Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not
possible' and terminate the function.
• Step 3: If it is Not Empty then, define two Node pointers 'temp1' and
'temp2' and initialize 'temp1' with head.
• Step 4: Check whether list has only one Node (temp1 → next == NULL)
• Step 5: If it is TRUE. Then, set head = NULL and delete temp1. And
terminate the function. (Setting Empty list condition)
• Step 6: If it is FALSE. Then, set 'temp2 = temp1 ' and move temp1 to its
next node. Repeat the same until it reaches to the last node in the list.
(until temp1 → next == NULL)
• Step 7: Finally, Set temp2 → next = NULL and delete temp1.
Deleting a Specific Node from the list
• We can use the following steps to delete a specific node from the single
linked list...
• Step 1: Check whether list is Empty (head == NULL)
• Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not
possible' and terminate the function.
• Step 3: If it is Not Empty then, define two Node pointers 'temp1' and
'temp2' and initialize 'temp1' with head.
• Step 4: Keep moving the temp1 until it reaches to the exact node to be
deleted or to the last node. And every time set 'temp2 = temp1' before
moving the 'temp1' to its next node.
• Step 5: If it is reached to the last node then display 'Given node not found
in the list! Deletion not possible!!!'. And terminate the function.
• Step 6: If it is reached to the exact node which we want to delete,
then check whether list is having only one node or not
• Step 7: If list has only one node and that is the node to be deleted,
then set head = NULL and delete temp1 (free(temp1)).
• Step 8: If list contains multiple nodes, then check whether temp1 is
the first node in the list (temp1 == head).
• Step 9: If temp1 is the first node then move the head to the next
node (head = head → next) and delete temp1.
• Step 10: If temp1 is not first node then check whether it is last node
in the list (temp1 → next == NULL).
• Step 11: If temp1 is last node then set temp2 → next = NULL and
delete temp1 (free(temp1)).
• Step 12: If temp1 is not first node and not last node then set temp2
→ next = temp1 → next and delete temp1 (free(temp1)).
Displaying a Single Linked List
• We can use the following steps to display the elements of a single
linked list...
• Step 1: Check whether list is Empty (head == NULL)
• Step 2: If it is Empty then, display 'List is Empty!!!' and terminate the
function.
• Step 3: If it is Not Empty then, define a Node pointer 'temp' and
initialize with head.
• Step 4: Keep displaying temp → data with an arrow (--->)
until temp reaches to the last node
• Step 5: Finally display temp → data with arrow pointing
to NULL (temp → data ---> NULL).
Circular Linked List
• In single linked list, every node points to its next node in
the sequence and the last node points NULL.
• But in circular linked list, every node points to its next node
in the sequence but the last node points to the first node
in the list.
• Circular linked list is a sequence of elements in which
every element has link to its next element in the
sequence and the last element has a link to the first
element in the sequence.
• 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
Circular Linked List
• Example
•
Operations - Circular Linked List
• In a circular linked list, we perform the following
operations...
• Insertion
• Deletion
• Display
• Before we implement actual operations, first we need
to setup empty list.
• First perform the following steps before implementing
actual operations.
Circular Linked List
• Before we implement actual operations, first we need to setup empty
list. First perform the following steps before implementing actual
operations.
• Step 1: Include all the header files which are used in the program.
• Step 2: Declare all the user defined functions.
• Step 3: Define a Node structure with two members data and next
• Step 4: Define a Node pointer 'head' and set it to NULL.
• Step 4: Implement the main method by displaying operations menu
and make suitable function calls in the main method to perform user
selected operation.
Insertion - Circular Linked List
•In a circular linked list, the insertion
operation can be performed in three ways.
They are as follows...
•Inserting At Beginning of the list
•Inserting At End of the list
•Inserting At Specific location in the list
Inserting At Beginning of the list
• We can use the following steps to insert a new node at beginning of the
circular linked list...
• Step 1: Create a newNode with given value.
• Step 2: Check whether list is Empty (head == NULL)
• Step 3: If it is Empty then,
set head = newNode and newNode→next = head .
• Step 4: If it is Not Empty then, define a Node pointer 'temp' and initialize
with 'head'.
• Step 5: Keep moving the 'temp' to its next node until it reaches to the last
node (until 'temp → next == head').
• Step 6: Set 'newNode → next =head', 'head = newNode' and 'temp →
next = head'.
Inserting At End of the list
• We can use the following steps to insert a new node at end of the
circular linked list...
• Step 1: Create a newNode with given value.
• Step 2: Check whether list is Empty (head == NULL).
• Step 3: If it is Empty then, set head = newNode and newNode →
next = head.
• Step 4: If it is Not Empty then, define a node pointer temp and
initialize with head.
• Step 5: Keep moving the temp to its next node until it reaches to the
last node in the list (until temp → next == head).
• Step 6: Set temp → next = newNode and newNode → next = head.
Inserting At Specific location in the list (After a
Node)
• We can use the following steps to insert a new node after a node in
the circular linked list...
• Step 1: Create a newNode with given value.
• Step 2: Check whether list is Empty (head == NULL)
• Step 3: If it is Empty then, set head = newNode and newNode →
next = head.
• Step 4: If it is Not Empty then, define a node pointer tempand
initialize with head.
• Step 5: Keep moving the temp to its next node until it reaches to the
node after which we want to insert the newNode (until temp1 →
data is equal to location, here location is the node value after which
we want to insert the newNode).
• Step 6: Every time check whether temp is reached to the last node or
not. If it is reached to last node then display 'Given node is not found
in the list!!! Insertion not possible!!!' and terminate the function.
Otherwise move the temp to next node.
• Step 7: If temp is reached to the exact node after which we want to
insert the newNode then check whether it is last node (temp → next
== head).
• Step 8: If temp is last node then set temp → next = newNode
and newNode → next = head.
• Step 9: If temp is not last node then set newNode → next = temp →
next and temp → next = newNode.
Deletion - Circular Linked List
•In a circular linked list, the deletion
operation can be performed in three ways
those are as follows...
•Deleting from Beginning of the list
•Deleting from End of the list
•Deleting a Specific Node
Deleting from Beginning of the list
• We can use the following steps to delete a node from beginning of the
circular linked list...
• Step 1: Check whether list is Empty (head == NULL)
• Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not
possible' and terminate the function.
• Step 3: If it is Not Empty then, define two Node pointers 'temp1' and
'temp2' and initialize both 'temp1' and 'temp2' with head.
• Step 4: Check whether list is having only one node (temp1 → next == head)
• Step 5: If it is TRUE then set head = NULL and
delete temp1(Setting Empty list conditions)
• Step 6: If it is FALSE move the temp1 until it reaches to the last node.
(until temp1 → next == head )
• Step 7: Then set head = temp2 → next, temp1 → next = head and
delete temp2.
Deleting from End of the list
• We can use the following steps to delete a node from end of the circular linked
list...
• Step 1: Check whether list is Empty (head == NULL)
• Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' and
terminate the function.
• Step 3: If it is Not Empty then, define two Node pointers 'temp1' and 'temp2' and
initialize 'temp1' with head.
• Step 4: Check whether list has only one Node (temp1 → next== head)
• Step 5: If it is TRUE. Then, set head = NULL and delete temp1. And terminate
from the function. (Setting Empty list condition)
• Step 6: If it is FALSE. Then, set 'temp2 = temp1 ' and move temp1 to its next
node. Repeat the same until temp1 reaches to the last node in the list.
(until temp1 → next == head)
• Step 7: Set temp2 → next = head and delete temp1.
Deleting a Specific Node from the list
• Step 1: Check whether list is Empty (head == NULL)
• Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not
possible' and terminate the function.
• Step 3: If it is Not Empty then, define two Node pointers 'temp1' and
'temp2' and initialize 'temp1' with head.
• Step 4: Keep moving the temp1 until it reaches to the exact node to be
deleted or to the last node. And every time set 'temp2 = temp1' before
moving the 'temp1' to its next node.
• Step 5: If it is reached to the last node then display 'Given node not found
in the list! Deletion not possible!!!'. And terminate the function.
• Step 6: If it is reached to the exact node which we want to delete, then
check whether list is having only one node (temp1 → next == head)
• Step 7: If list has only one node and that is the node to be deleted then
set head = NULL and delete temp1(free(temp1)).
• Step 8: If list contains multiple nodes then check whether temp1 is the first
node in the list (temp1 == head).
• Step 9: If temp1 is the first node then set temp2 = head and keep
moving temp2 to its next node until temp2 reaches to the last node. Then
set head = head → next, temp2 → next = head and delete temp1.
• Step 10: If temp1 is not first node then check whether it is last node in the
list (temp1 → next == head).
• Step 11: If temp1 is last node then set temp2 → next = headand
delete temp1 (free(temp1)).
• Step 12: If temp1 is not first node and not last node then set temp2 →
next = temp1 → next and delete temp1(free(temp1)).
Displaying a circular Linked List
• We can use the following steps to display the elements of a circular linked
list...
• Step 1: Check whether list is Empty (head == NULL)
• Step 2: If it is Empty, then display 'List is Empty!!!' and terminate the
function.
• Step 3: If it is Not Empty then, define a Node pointer 'temp’ and initialize
with head.
• Step 4: Keep displaying temp → data with an arrow (--->)
until temp reaches to the last node
• Step 5: Finally display temp → data with arrow pointing to head → data.
Double Linked List
• In a single linked list, every node has link to its next node in the
sequence.
• So, we can traverse from one node to other node only in one
direction and we can not traverse back.
• We can solve this kind of problem by using double linked list. Double
linked list can be defined as follows...
• Double linked list is a sequence of elements in which every element
has links to its previous element and next element in the sequence.
Double Linked List
• In double linked list, every node has link to its previous node and next
node. So, we can traverse forward by using next field and can traverse
backward by using previous field. Every node in a double linked list
contains three fields and they are shown in the following figure...
• Here, 'link1' field is used to store the address of the previous node in the
sequence, 'link2' field is used to store the address of the next node in the
sequence and 'data' field is used to store the actual value of that node.
Operations- Double Linked List
•In a double linked list, we perform the
following operations...
•Insertion
•Deletion
•Display
Insertion - Double Linked List
•In a double linked list, the insertion operation
can be performed in three ways as follows...
•Inserting At Beginning of the list
•Inserting At End of the list
•Inserting At Specific location in the list
Inserting At Beginning of the list
• We can use the following steps to insert a new node
at beginning of the double linked list...
• Step 1: Create a newNode with given value
and newNode → previous as NULL.
• Step 2: Check whether list is Empty (head == NULL)
• Step 3: If it is Empty then, assign NULL to newNode →
next and newNode to head.
Step 4: If it is not Empty then, assign head to newNode
→ next and newNode to head.
Inserting At End of the list
• We can use the following steps to insert a new node at end of the
double linked list...
• Step 1: Create a newNode with given value and newNode →
next as NULL.
• Step 2: Check whether list is Empty (head == NULL)
• Step 3: If it is Empty, then assign NULL to newNode →
previous and newNode to head.
• Step 4: If it is not Empty, then, define a node pointer tempand
initialize with head.
• Step 5: Keep moving the temp to its next node until it reaches to the
last node in the list (until temp → next is equal to NULL).
• Step 6: Assign newNode to temp → next and temp to newNode →
previous.
Inserting At Specific location in the list (After a
Node)
• Step 1: Create a newNode with given value.
• Step 2: Check whether list is Empty (head == NULL)
• Step 3: If it is Empty then, assign NULL to newNode →
previous & newNode → next and newNode to head.
• Step 4: If it is not Empty then, define two node
pointers temp1 & temp2 and initialize temp1 with head.
• Step 5: Keep moving the temp1 to its next node until it reaches to the
node after which we want to insert the newNode (until temp1 →
data is equal to location, here location is the node value after which
we want to insert the newNode).
• Step 6: Every time check whether temp1 is reached to the last node.
• If it is reached to the last node then display 'Given node is not found
in the list!!! Insertion not possible!!!' and terminate the function.
Otherwise move the temp1 to next node.
• Step 7: Assign temp1 → next to temp2, newNode to temp1 →
next, temp1 to newNode → previous, temp2 to newNode →
next and newNode to temp2 → previous.
Deletion - Double Linked List
•In a double linked list, the deletion
operation can be performed in three ways
as follows...
•Deleting from Beginning of the list
•Deleting from End of the list
•Deleting a Specific Node
Deleting from Beginning of the list
• We can use the following steps to delete a node from beginning of
the double linked list...
• Step 1: Check whether list is Empty (head == NULL)
• Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not
possible' and terminate the function.
• Step 3: If it is not Empty then, define a Node pointer 'temp’ and
initialize with head.
• Step 4: Check whether list is having only one node (temp →
previous is equal to temp → next)
• Step 5: If it is TRUE, then set head to NULL and
delete temp(Setting Empty list conditions)
• Step 6: If it is FALSE, then assign temp → next to head, NULL to head
→ previous and delete temp.
Deleting from End of the list
• We can use the following steps to delete a node from end of the double linked list...
• Step 1: Check whether list is Empty (head == NULL)
• Step 2: If it is Empty, then display 'List is Empty!!! Deletion is not possible' and
terminate the function.
• Step 3: If it is not Empty then, define a Node pointer 'temp’ and initialize with head.
• Step 4: Check whether list has only one Node (temp → previous and temp → next both
are NULL)
• Step 5: If it is TRUE, then assign NULL to head and delete temp. And terminate from the
function. (Setting Empty list condition)
• Step 6: If it is FALSE, then keep moving temp until it reaches to the last node in the list.
(until temp → next is equal to NULL)
• Step 7: Assign NULL to temp → previous → next and delete temp.
Deleting a Specific Node from the list
• We can use the following steps to delete a specific node from the
double linked list...
• Step 1: Check whether list is Empty (head == NULL)
• Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not
possible' and terminate the function.
• Step 3: If it is not Empty, then define a Node pointer 'temp’ and
initialize with head.
• Step 4: Keep moving the temp until it reaches to the exact node to be
deleted or to the last node.
• Step 5: If it is reached to the last node, then display 'Given node not
found in the list! Deletion not possible!!!' and terminate the
function.
• Step 6: If it is reached to the exact node which we want to delete, then
check whether list is having only one node or not
• Step 7: If list has only one node and that is the node which is to be deleted
then set head to NULL and delete temp(free(temp)).
• Step 8: If list contains multiple nodes, then check whether temp is the first
node in the list (temp == head).
• Step 9: If temp is the first node, then move the head to the next node
(head = head → next), set head of previous to NULL (head → previous =
NULL) and delete temp.
• Step 10: If temp is not the first node, then check whether it is the last node
in the list (temp → next == NULL).
• Step 11: If temp is the last node then
set temp of previous of next to NULL (temp → previous → next = NULL)
and delete temp (free(temp)).
• Step 12: If temp is not the first node and not the last node, then
set temp of previous of next to temp of next (temp → previous → next =
temp → next), temp of next of previous to temp of previous (temp → next
→ previous = temp → previous) and delete temp (free(temp)).
Displaying a Double Linked List
• We can use the following steps to display the elements of a double
linked list...
• Step 1: Check whether list is Empty (head == NULL)
• Step 2: If it is Empty, then display 'List is Empty!!!' and terminate the
function.
• Step 3: If it is not Empty, then define a Node pointer 'temp’ and
initialize with head.
• Step 4: Display 'NULL <--- '.
• Step 5: Keep displaying temp → data with an arrow (<===>)
until temp reaches to the last node
• Step 6: Finally, display temp → data with arrow pointing
to NULL (temp → data ---> NULL).
Application of Linked List
•Large Numeric Arithmetic
•Optimum Utilization of Memory Space
•Represent Complex Structure – Tree, Graph

More Related Content

What's hot

Filipino 9 (Noli Me Tangere): Kabanata 1 (Nakikilala ang mga Tauhan batay sa ...
Filipino 9 (Noli Me Tangere): Kabanata 1 (Nakikilala ang mga Tauhan batay sa ...Filipino 9 (Noli Me Tangere): Kabanata 1 (Nakikilala ang mga Tauhan batay sa ...
Filipino 9 (Noli Me Tangere): Kabanata 1 (Nakikilala ang mga Tauhan batay sa ...Juan Miguel Palero
 
Mga Komunikatibong Pahayag sa Pagbuo ng Kampanyang Panlipunan.pptx
Mga Komunikatibong Pahayag sa Pagbuo ng Kampanyang Panlipunan.pptxMga Komunikatibong Pahayag sa Pagbuo ng Kampanyang Panlipunan.pptx
Mga Komunikatibong Pahayag sa Pagbuo ng Kampanyang Panlipunan.pptxMichaelaLugtu2
 
Esp 9 Pagtitimpi
Esp 9 PagtitimpiEsp 9 Pagtitimpi
Esp 9 Pagtitimpiedmond84
 
G8 Check Condition of Tools and Equipment and Perform.pptx
G8 Check Condition of Tools and Equipment and Perform.pptxG8 Check Condition of Tools and Equipment and Perform.pptx
G8 Check Condition of Tools and Equipment and Perform.pptxDhadaTedCortezano
 
Lesson 7 protocols (processes) in making electrical gadgets final
Lesson 7 protocols (processes) in making electrical gadgets finalLesson 7 protocols (processes) in making electrical gadgets final
Lesson 7 protocols (processes) in making electrical gadgets finaljoemariearaneta1
 
Dressmakig LAS week3.docx
Dressmakig LAS week3.docxDressmakig LAS week3.docx
Dressmakig LAS week3.docxFlorameOate1
 
Making simple electrical gadgets
Making simple electrical gadgetsMaking simple electrical gadgets
Making simple electrical gadgetsRey Obligacion
 
Management of Family Resources.pdf
Management of Family Resources.pdfManagement of Family Resources.pdf
Management of Family Resources.pdfDinahbelleJavierCasu
 
Angkop na mga Pahayag sa Panimula, Gitna, at Wakas.pptx
Angkop na mga Pahayag sa Panimula, Gitna, at Wakas.pptxAngkop na mga Pahayag sa Panimula, Gitna, at Wakas.pptx
Angkop na mga Pahayag sa Panimula, Gitna, at Wakas.pptxbhe pestijo
 
Common-Faults-Using-HANDTOOLS.pptx
Common-Faults-Using-HANDTOOLS.pptxCommon-Faults-Using-HANDTOOLS.pptx
Common-Faults-Using-HANDTOOLS.pptxRachelleAI
 
Salitang ugat at panlapi sa pandiwa
Salitang ugat at panlapi sa pandiwaSalitang ugat at panlapi sa pandiwa
Salitang ugat at panlapi sa pandiwaJanna Marie Ballo
 
Revised-taxonomy-ng-bloom-filipino.docx
Revised-taxonomy-ng-bloom-filipino.docxRevised-taxonomy-ng-bloom-filipino.docx
Revised-taxonomy-ng-bloom-filipino.docxJINKYRAMIREZ1
 

What's hot (20)

Filipino 9 (Noli Me Tangere): Kabanata 1 (Nakikilala ang mga Tauhan batay sa ...
Filipino 9 (Noli Me Tangere): Kabanata 1 (Nakikilala ang mga Tauhan batay sa ...Filipino 9 (Noli Me Tangere): Kabanata 1 (Nakikilala ang mga Tauhan batay sa ...
Filipino 9 (Noli Me Tangere): Kabanata 1 (Nakikilala ang mga Tauhan batay sa ...
 
Mga Komunikatibong Pahayag sa Pagbuo ng Kampanyang Panlipunan.pptx
Mga Komunikatibong Pahayag sa Pagbuo ng Kampanyang Panlipunan.pptxMga Komunikatibong Pahayag sa Pagbuo ng Kampanyang Panlipunan.pptx
Mga Komunikatibong Pahayag sa Pagbuo ng Kampanyang Panlipunan.pptx
 
Esp 9 Pagtitimpi
Esp 9 PagtitimpiEsp 9 Pagtitimpi
Esp 9 Pagtitimpi
 
G8 Check Condition of Tools and Equipment and Perform.pptx
G8 Check Condition of Tools and Equipment and Perform.pptxG8 Check Condition of Tools and Equipment and Perform.pptx
G8 Check Condition of Tools and Equipment and Perform.pptx
 
Lesson 7 protocols (processes) in making electrical gadgets final
Lesson 7 protocols (processes) in making electrical gadgets finalLesson 7 protocols (processes) in making electrical gadgets final
Lesson 7 protocols (processes) in making electrical gadgets final
 
Esp 2
Esp 2Esp 2
Esp 2
 
Agri 5 lesson 3
Agri 5 lesson 3Agri 5 lesson 3
Agri 5 lesson 3
 
esp MODYUL 9 ICARE.pptx
esp MODYUL 9 ICARE.pptxesp MODYUL 9 ICARE.pptx
esp MODYUL 9 ICARE.pptx
 
Dressmakig LAS week3.docx
Dressmakig LAS week3.docxDressmakig LAS week3.docx
Dressmakig LAS week3.docx
 
Making simple electrical gadgets
Making simple electrical gadgetsMaking simple electrical gadgets
Making simple electrical gadgets
 
Management of Family Resources.pdf
Management of Family Resources.pdfManagement of Family Resources.pdf
Management of Family Resources.pdf
 
Angkop na mga Pahayag sa Panimula, Gitna, at Wakas.pptx
Angkop na mga Pahayag sa Panimula, Gitna, at Wakas.pptxAngkop na mga Pahayag sa Panimula, Gitna, at Wakas.pptx
Angkop na mga Pahayag sa Panimula, Gitna, at Wakas.pptx
 
Marcotting
MarcottingMarcotting
Marcotting
 
Common-Faults-Using-HANDTOOLS.pptx
Common-Faults-Using-HANDTOOLS.pptxCommon-Faults-Using-HANDTOOLS.pptx
Common-Faults-Using-HANDTOOLS.pptx
 
Nail care manicuredesign
Nail care manicuredesignNail care manicuredesign
Nail care manicuredesign
 
Product Development
Product DevelopmentProduct Development
Product Development
 
pabula.pptx
pabula.pptxpabula.pptx
pabula.pptx
 
Salitang ugat at panlapi sa pandiwa
Salitang ugat at panlapi sa pandiwaSalitang ugat at panlapi sa pandiwa
Salitang ugat at panlapi sa pandiwa
 
Revised-taxonomy-ng-bloom-filipino.docx
Revised-taxonomy-ng-bloom-filipino.docxRevised-taxonomy-ng-bloom-filipino.docx
Revised-taxonomy-ng-bloom-filipino.docx
 
Edukasyon sa Pagpapakatao Grade 9 Learner's Material
Edukasyon sa Pagpapakatao Grade 9 Learner's MaterialEdukasyon sa Pagpapakatao Grade 9 Learner's Material
Edukasyon sa Pagpapakatao Grade 9 Learner's Material
 

Similar to Arrays and linked lists

1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptxBlueSwede
 
LinkedList Presentation.pptx
LinkedList Presentation.pptxLinkedList Presentation.pptx
LinkedList Presentation.pptxwahid431192
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptxDr.Shweta
 
mbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptxmbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptxjotaro11
 
VCE Unit 02 (1).pptx
VCE Unit 02 (1).pptxVCE Unit 02 (1).pptx
VCE Unit 02 (1).pptxskilljiolms
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.pptSeethaDinesh
 
Data structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxData structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxAhmedEldesoky24
 
21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptxreddy19841
 
DS Module1 (1).pptx
DS Module1 (1).pptxDS Module1 (1).pptx
DS Module1 (1).pptxAnuJoseph95
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5Kumar
 
Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02Getachew Ganfur
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3infanciaj
 

Similar to Arrays and linked lists (20)

Linked list
Linked listLinked list
Linked list
 
ds bridge.pptx
ds bridge.pptxds bridge.pptx
ds bridge.pptx
 
1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx
 
LinkedList Presentation.pptx
LinkedList Presentation.pptxLinkedList Presentation.pptx
LinkedList Presentation.pptx
 
day 13.pptx
day 13.pptxday 13.pptx
day 13.pptx
 
lecture 02.2.ppt
lecture 02.2.pptlecture 02.2.ppt
lecture 02.2.ppt
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
 
mbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptxmbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptx
 
VCE Unit 02 (1).pptx
VCE Unit 02 (1).pptxVCE Unit 02 (1).pptx
VCE Unit 02 (1).pptx
 
Unit 4
Unit 4Unit 4
Unit 4
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked list
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Data structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxData structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptx
 
21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx
 
DS Module1 (1).pptx
DS Module1 (1).pptxDS Module1 (1).pptx
DS Module1 (1).pptx
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
 
Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
 

Recently uploaded

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 

Recently uploaded (20)

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 

Arrays and linked lists

  • 3. Arrays Intro • Do you listen to music on your smartphone? • Do you keep a list of contacts on your phone? • If your answer is “yes” to any of these questions, then it’s almost certain that you’ve used arrays and you didn’t even know it! ? • Arrays are very powerful data structures that store lists of elements. • They have endless applications. They are very important in the world of computer science. • To understand how they work, it’s very helpful to visualize your computer’s memory as a grid, just like the one below. Each piece of information is stored in one of those small elements (squares) that make the grid.
  • 5. Arrays • Whenever we want to work with large number of data values, we need to use that much number of different variables. • As the number of variables are increasing, complexity of the program also increases and programmers get confused with the variable names. • There may be situations in which we need to work with large number of similar data values. • To make this work more easy, C or any programming language provides a concept called "Array".
  • 6. Arrays • An array is a variable which can store multiple values of same data type at a time. • An array can also be defined as follows... • "Collection of similar data items stored in continuous memory locations with single name". • Arrays are classified as Homogeneous Data Structures because they store elements of the same type. • They can store numbers, strings, Boolean values (true and false), characters, objects, and so on. • But once you define the type of values that your array will store, all its elements must be of that same type. You can’t “mix” different types of data.
  • 7.
  • 8.
  • 9. When you create an array, you: • - Assign it to a variable. ? - Define the type of elements that it will store. ? - Define its size (the maximum number of elements). ? • Int myArray [5]; • But how can you tell the computer which particular value you would like to access? This is where indices take a vital role!
  • 10. Indices • You use what it’s called an “index” (“indices” in plural) to access a value in an array. This is a number that refers to the location where the value is stored. • As you can see in the diagram below, the first element in the array is referred to using index 0. As you move further to the right, the index increases by one for each space in memory.
  • 11. The general syntax to access an element is: <ArrayVariable>[index>] • For example: • If your array is stored in the variable myArray and you want to access the first element (at index 0), you would use myArray[0]
  • 12. Memory • Now that you know how to access values, let’s see how arrays are stored in your computer’s memory. When you define the size of the array, all of that space in memory is “reserved” from that moment on for future values that you may want to insert. • Note: If you do not fill the array with values, that space will be kept reserved and empty until you do. • For Example: Let’s say that you define an array of size 5 but only insert one value. All that remaining space will be empty and “reserved” in memory, waiting for future assignments.
  • 13. Operations on Array: Insertion • Let’s say that we have an array of size 6 and there’s still an empty space. • We want to insert an element “e” at the beginning of the array (index 0), but this place is already taken by the element “a” • What should we do? •
  • 14. • Note: You will need to create a variable to keep track of the last index that contains elements. In the diagram above, the array is filled up to index 4 before the insertion. This way, you can determine if the array is full and what index you should use to insert an element at the end. • After doing this, our element is successfully inserted. ?
  • 15. Wait a minute! What Happens if the Array is Full? • In this case, you need to create a new, larger array and manually copy all the elements into this new array. This operation is very expensive, time-wise. Imagine what would happen if you had an array with millions of elements! That could take a very long time to complete.
  • 16. Deletion operation of Array • Now let’s say that you want to delete an element from the array. • • To maintain the efficiency of random access (being able to access the array through an index extremely fast) the elements must be stored in contiguous spaces of memory. • You can’t just delete the element and leave that space empty.
  • 17. • You should move the elements that come after the element that you want to delete one index the left. • And finally, you have this resulting array ?. As you can see, “b” has been successfully deleted. • •
  • 18. Finding an Element • You have three options to find an element in an array: • If you know where it’s located, use the index. • If you don’t know where it’s located and your data is sorted, you can use algorithms to optimize your search, such as Binary Search. • If you don’t know where it’s located and your data is not sorted, you will need to search through every element in the array and check if the current element is the element you are looking for
  • 19. Linked List • When we want to work with unknown number of data values, we use a linked list data structure to organize that data. • Linked list is a linear data structure that contains sequence of elements such that each element links to its next element in the sequence. • Each element in a linked list is called as "Node". • Types: single, double and circular linked lists
  • 20. What is Single Linked List? • Simply a list is a sequence of data, and linked list is a sequence of data linked with each other. • Single linked list is a sequence of elements in which every element has link to its next element in the sequence. • In any single linked list, the individual element is called as "Node". • Every "Node" contains two fields, data and next. • The data field is used to store actual value of that node and next field is used to store the address of the next node in the sequence.
  • 21. Single Linked List • The graphical representation of a node in a single linked list is as follows... • In a single linked list, the address of the first node is always stored in a reference node known as "front" (Some times it is also known as "head"). • Always next part (reference part) of the last node must be NULL.
  • 23. Operations - Single Linked List •In a single linked list we perform the following operations... •Insertion •Deletion •Display
  • 24. Perform the following steps before implementing actual operations • Before we implement actual operations, first we need to setup empty list. First perform the following steps before implementing actual operations. • Step 1: Include all the header files which are used in the program. • Step 2: Declare all the user defined functions. • Step 3: Define a Node structure with two members data and next • Step 4: Define a Node pointer 'head' and set it to NULL. • Step 4: Implement the main method by displaying operations menu and make suitable function calls in the main method to perform user selected operation.
  • 25. Insertion - Single Linked List •In a single linked list, the insertion operation can be performed in three ways. They are as follows... •Inserting At Beginning of the list •Inserting At End of the list •Inserting At Specific location in the list
  • 26. Inserting At Beginning of the list •We can use the following steps to insert a new node at beginning of the single linked list... •Step 1: Create a newNode with given value. •Step 2: Check whether list is Empty (head == NULL) •Step 3: If it is Empty then, set newNode→next = NULL and head = newNode. •Step 4: If it is Not Empty then, set newNode→next = head and head = newNode.
  • 27. Inserting At End of the list • We can use the following steps to insert a new node at end of the single linked list... • Step 1: Create a newNode with given value and newNode → next as NULL. • Step 2: Check whether list is Empty (head == NULL). • Step 3: If it is Empty then, set head = newNode. • Step 4: If it is Not Empty then, define a node pointer temp and initialize with head. • Step 5: Keep moving the temp to its next node until it reaches to the last node in the list (until temp → next is equal to NULL). • Step 6: Set temp → next = newNode.
  • 28. Inserting At Specific location in the list (After a Node) • We can use the following steps to insert a new node after a node in the single linked list... • Step 1: Create a newNode with given value. • Step 2: Check whether list is Empty (head == NULL) • Step 3: If it is Empty then, set newNode → next = NULL and head = newNode. • Step 4: If it is Not Empty then, define a node pointer temp and initialize with head. • Step 5: Keep moving the temp to its next node until it reaches to the node after which we want to insert the newNode (until temp1 → data is equal to location, here location is the node value after which we want to insert the newNode). • Step 6: Every time check whether temp is reached to last node or not. If it is reached to last node then display 'Given node is not found in the list!!! Insertion not possible!!!' and terminate the function. Otherwise move the temp to next node. • Step 7: Finally, Set 'newNode → next = temp → next' and 'temp → next = newNode'
  • 29. Deletion - Single Linked List • In a single linked list, the deletion operation can be performed in three ways. They are as follows... • Deleting from Beginning of the list • Deleting from End of the list • Deleting a Specific Node
  • 30. Deleting from Beginning of the list • We can use the following steps to delete a node from beginning of the single linked list... • Step 1: Check whether list is Empty (head == NULL) • Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function. • Step 3: If it is Not Empty then, define a Node pointer 'temp' and initialize with head. • Step 4: Check whether list is having only one node (temp → next == NULL) • Step 5: If it is TRUE then set head = NULL and delete temp (Setting Empty list conditions) • Step 6: If it is FALSE then set head = temp → next, and delete temp.
  • 31. Deleting from End of the list • We can use the following steps to delete a node from end of the single linked list... • Step 1: Check whether list is Empty (head == NULL) • Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function. • Step 3: If it is Not Empty then, define two Node pointers 'temp1' and 'temp2' and initialize 'temp1' with head. • Step 4: Check whether list has only one Node (temp1 → next == NULL) • Step 5: If it is TRUE. Then, set head = NULL and delete temp1. And terminate the function. (Setting Empty list condition) • Step 6: If it is FALSE. Then, set 'temp2 = temp1 ' and move temp1 to its next node. Repeat the same until it reaches to the last node in the list. (until temp1 → next == NULL) • Step 7: Finally, Set temp2 → next = NULL and delete temp1.
  • 32. Deleting a Specific Node from the list • We can use the following steps to delete a specific node from the single linked list... • Step 1: Check whether list is Empty (head == NULL) • Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function. • Step 3: If it is Not Empty then, define two Node pointers 'temp1' and 'temp2' and initialize 'temp1' with head. • Step 4: Keep moving the temp1 until it reaches to the exact node to be deleted or to the last node. And every time set 'temp2 = temp1' before moving the 'temp1' to its next node. • Step 5: If it is reached to the last node then display 'Given node not found in the list! Deletion not possible!!!'. And terminate the function.
  • 33. • Step 6: If it is reached to the exact node which we want to delete, then check whether list is having only one node or not • Step 7: If list has only one node and that is the node to be deleted, then set head = NULL and delete temp1 (free(temp1)). • Step 8: If list contains multiple nodes, then check whether temp1 is the first node in the list (temp1 == head). • Step 9: If temp1 is the first node then move the head to the next node (head = head → next) and delete temp1. • Step 10: If temp1 is not first node then check whether it is last node in the list (temp1 → next == NULL). • Step 11: If temp1 is last node then set temp2 → next = NULL and delete temp1 (free(temp1)). • Step 12: If temp1 is not first node and not last node then set temp2 → next = temp1 → next and delete temp1 (free(temp1)).
  • 34. Displaying a Single Linked List • We can use the following steps to display the elements of a single linked list... • Step 1: Check whether list is Empty (head == NULL) • Step 2: If it is Empty then, display 'List is Empty!!!' and terminate the function. • Step 3: If it is Not Empty then, define a Node pointer 'temp' and initialize with head. • Step 4: Keep displaying temp → data with an arrow (--->) until temp reaches to the last node • Step 5: Finally display temp → data with arrow pointing to NULL (temp → data ---> NULL).
  • 35. Circular Linked List • In single linked list, every node points to its next node in the sequence and the last node points NULL. • But in circular linked list, every node points to its next node in the sequence but the last node points to the first node in the list. • Circular linked list is a sequence of elements in which every element has link to its next element in the sequence and the last element has a link to the first element in the sequence. • 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
  • 37. Operations - Circular Linked List • In a circular linked list, we perform the following operations... • Insertion • Deletion • Display • Before we implement actual operations, first we need to setup empty list. • First perform the following steps before implementing actual operations.
  • 38. Circular Linked List • Before we implement actual operations, first we need to setup empty list. First perform the following steps before implementing actual operations. • Step 1: Include all the header files which are used in the program. • Step 2: Declare all the user defined functions. • Step 3: Define a Node structure with two members data and next • Step 4: Define a Node pointer 'head' and set it to NULL. • Step 4: Implement the main method by displaying operations menu and make suitable function calls in the main method to perform user selected operation.
  • 39. Insertion - Circular Linked List •In a circular linked list, the insertion operation can be performed in three ways. They are as follows... •Inserting At Beginning of the list •Inserting At End of the list •Inserting At Specific location in the list
  • 40. Inserting At Beginning of the list • We can use the following steps to insert a new node at beginning of the circular linked list... • Step 1: Create a newNode with given value. • Step 2: Check whether list is Empty (head == NULL) • Step 3: If it is Empty then, set head = newNode and newNode→next = head . • Step 4: If it is Not Empty then, define a Node pointer 'temp' and initialize with 'head'. • Step 5: Keep moving the 'temp' to its next node until it reaches to the last node (until 'temp → next == head'). • Step 6: Set 'newNode → next =head', 'head = newNode' and 'temp → next = head'.
  • 41. Inserting At End of the list • We can use the following steps to insert a new node at end of the circular linked list... • Step 1: Create a newNode with given value. • Step 2: Check whether list is Empty (head == NULL). • Step 3: If it is Empty then, set head = newNode and newNode → next = head. • Step 4: If it is Not Empty then, define a node pointer temp and initialize with head. • Step 5: Keep moving the temp to its next node until it reaches to the last node in the list (until temp → next == head). • Step 6: Set temp → next = newNode and newNode → next = head.
  • 42. Inserting At Specific location in the list (After a Node) • We can use the following steps to insert a new node after a node in the circular linked list... • Step 1: Create a newNode with given value. • Step 2: Check whether list is Empty (head == NULL) • Step 3: If it is Empty then, set head = newNode and newNode → next = head. • Step 4: If it is Not Empty then, define a node pointer tempand initialize with head. • Step 5: Keep moving the temp to its next node until it reaches to the node after which we want to insert the newNode (until temp1 → data is equal to location, here location is the node value after which we want to insert the newNode).
  • 43. • Step 6: Every time check whether temp is reached to the last node or not. If it is reached to last node then display 'Given node is not found in the list!!! Insertion not possible!!!' and terminate the function. Otherwise move the temp to next node. • Step 7: If temp is reached to the exact node after which we want to insert the newNode then check whether it is last node (temp → next == head). • Step 8: If temp is last node then set temp → next = newNode and newNode → next = head. • Step 9: If temp is not last node then set newNode → next = temp → next and temp → next = newNode.
  • 44. Deletion - Circular Linked List •In a circular linked list, the deletion operation can be performed in three ways those are as follows... •Deleting from Beginning of the list •Deleting from End of the list •Deleting a Specific Node
  • 45. Deleting from Beginning of the list • We can use the following steps to delete a node from beginning of the circular linked list... • Step 1: Check whether list is Empty (head == NULL) • Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function. • Step 3: If it is Not Empty then, define two Node pointers 'temp1' and 'temp2' and initialize both 'temp1' and 'temp2' with head. • Step 4: Check whether list is having only one node (temp1 → next == head) • Step 5: If it is TRUE then set head = NULL and delete temp1(Setting Empty list conditions) • Step 6: If it is FALSE move the temp1 until it reaches to the last node. (until temp1 → next == head ) • Step 7: Then set head = temp2 → next, temp1 → next = head and delete temp2.
  • 46. Deleting from End of the list • We can use the following steps to delete a node from end of the circular linked list... • Step 1: Check whether list is Empty (head == NULL) • Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function. • Step 3: If it is Not Empty then, define two Node pointers 'temp1' and 'temp2' and initialize 'temp1' with head. • Step 4: Check whether list has only one Node (temp1 → next== head) • Step 5: If it is TRUE. Then, set head = NULL and delete temp1. And terminate from the function. (Setting Empty list condition) • Step 6: If it is FALSE. Then, set 'temp2 = temp1 ' and move temp1 to its next node. Repeat the same until temp1 reaches to the last node in the list. (until temp1 → next == head) • Step 7: Set temp2 → next = head and delete temp1.
  • 47. Deleting a Specific Node from the list • Step 1: Check whether list is Empty (head == NULL) • Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function. • Step 3: If it is Not Empty then, define two Node pointers 'temp1' and 'temp2' and initialize 'temp1' with head. • Step 4: Keep moving the temp1 until it reaches to the exact node to be deleted or to the last node. And every time set 'temp2 = temp1' before moving the 'temp1' to its next node. • Step 5: If it is reached to the last node then display 'Given node not found in the list! Deletion not possible!!!'. And terminate the function. • Step 6: If it is reached to the exact node which we want to delete, then check whether list is having only one node (temp1 → next == head)
  • 48. • Step 7: If list has only one node and that is the node to be deleted then set head = NULL and delete temp1(free(temp1)). • Step 8: If list contains multiple nodes then check whether temp1 is the first node in the list (temp1 == head). • Step 9: If temp1 is the first node then set temp2 = head and keep moving temp2 to its next node until temp2 reaches to the last node. Then set head = head → next, temp2 → next = head and delete temp1. • Step 10: If temp1 is not first node then check whether it is last node in the list (temp1 → next == head). • Step 11: If temp1 is last node then set temp2 → next = headand delete temp1 (free(temp1)). • Step 12: If temp1 is not first node and not last node then set temp2 → next = temp1 → next and delete temp1(free(temp1)).
  • 49. Displaying a circular Linked List • We can use the following steps to display the elements of a circular linked list... • Step 1: Check whether list is Empty (head == NULL) • Step 2: If it is Empty, then display 'List is Empty!!!' and terminate the function. • Step 3: If it is Not Empty then, define a Node pointer 'temp’ and initialize with head. • Step 4: Keep displaying temp → data with an arrow (--->) until temp reaches to the last node • Step 5: Finally display temp → data with arrow pointing to head → data.
  • 50. Double Linked List • In a single linked list, every node has link to its next node in the sequence. • So, we can traverse from one node to other node only in one direction and we can not traverse back. • We can solve this kind of problem by using double linked list. Double linked list can be defined as follows... • Double linked list is a sequence of elements in which every element has links to its previous element and next element in the sequence.
  • 51. Double Linked List • In double linked list, every node has link to its previous node and next node. So, we can traverse forward by using next field and can traverse backward by using previous field. Every node in a double linked list contains three fields and they are shown in the following figure... • Here, 'link1' field is used to store the address of the previous node in the sequence, 'link2' field is used to store the address of the next node in the sequence and 'data' field is used to store the actual value of that node.
  • 52. Operations- Double Linked List •In a double linked list, we perform the following operations... •Insertion •Deletion •Display
  • 53. Insertion - Double Linked List •In a double linked list, the insertion operation can be performed in three ways as follows... •Inserting At Beginning of the list •Inserting At End of the list •Inserting At Specific location in the list
  • 54. Inserting At Beginning of the list • We can use the following steps to insert a new node at beginning of the double linked list... • Step 1: Create a newNode with given value and newNode → previous as NULL. • Step 2: Check whether list is Empty (head == NULL) • Step 3: If it is Empty then, assign NULL to newNode → next and newNode to head. Step 4: If it is not Empty then, assign head to newNode → next and newNode to head.
  • 55. Inserting At End of the list • We can use the following steps to insert a new node at end of the double linked list... • Step 1: Create a newNode with given value and newNode → next as NULL. • Step 2: Check whether list is Empty (head == NULL) • Step 3: If it is Empty, then assign NULL to newNode → previous and newNode to head. • Step 4: If it is not Empty, then, define a node pointer tempand initialize with head. • Step 5: Keep moving the temp to its next node until it reaches to the last node in the list (until temp → next is equal to NULL). • Step 6: Assign newNode to temp → next and temp to newNode → previous.
  • 56. Inserting At Specific location in the list (After a Node) • Step 1: Create a newNode with given value. • Step 2: Check whether list is Empty (head == NULL) • Step 3: If it is Empty then, assign NULL to newNode → previous & newNode → next and newNode to head. • Step 4: If it is not Empty then, define two node pointers temp1 & temp2 and initialize temp1 with head. • Step 5: Keep moving the temp1 to its next node until it reaches to the node after which we want to insert the newNode (until temp1 → data is equal to location, here location is the node value after which we want to insert the newNode).
  • 57. • Step 6: Every time check whether temp1 is reached to the last node. • If it is reached to the last node then display 'Given node is not found in the list!!! Insertion not possible!!!' and terminate the function. Otherwise move the temp1 to next node. • Step 7: Assign temp1 → next to temp2, newNode to temp1 → next, temp1 to newNode → previous, temp2 to newNode → next and newNode to temp2 → previous.
  • 58. Deletion - Double Linked List •In a double linked list, the deletion operation can be performed in three ways as follows... •Deleting from Beginning of the list •Deleting from End of the list •Deleting a Specific Node
  • 59. Deleting from Beginning of the list • We can use the following steps to delete a node from beginning of the double linked list... • Step 1: Check whether list is Empty (head == NULL) • Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function. • Step 3: If it is not Empty then, define a Node pointer 'temp’ and initialize with head. • Step 4: Check whether list is having only one node (temp → previous is equal to temp → next) • Step 5: If it is TRUE, then set head to NULL and delete temp(Setting Empty list conditions) • Step 6: If it is FALSE, then assign temp → next to head, NULL to head → previous and delete temp.
  • 60. Deleting from End of the list • We can use the following steps to delete a node from end of the double linked list... • Step 1: Check whether list is Empty (head == NULL) • Step 2: If it is Empty, then display 'List is Empty!!! Deletion is not possible' and terminate the function. • Step 3: If it is not Empty then, define a Node pointer 'temp’ and initialize with head. • Step 4: Check whether list has only one Node (temp → previous and temp → next both are NULL) • Step 5: If it is TRUE, then assign NULL to head and delete temp. And terminate from the function. (Setting Empty list condition) • Step 6: If it is FALSE, then keep moving temp until it reaches to the last node in the list. (until temp → next is equal to NULL) • Step 7: Assign NULL to temp → previous → next and delete temp.
  • 61. Deleting a Specific Node from the list • We can use the following steps to delete a specific node from the double linked list... • Step 1: Check whether list is Empty (head == NULL) • Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function. • Step 3: If it is not Empty, then define a Node pointer 'temp’ and initialize with head. • Step 4: Keep moving the temp until it reaches to the exact node to be deleted or to the last node. • Step 5: If it is reached to the last node, then display 'Given node not found in the list! Deletion not possible!!!' and terminate the function.
  • 62. • Step 6: If it is reached to the exact node which we want to delete, then check whether list is having only one node or not • Step 7: If list has only one node and that is the node which is to be deleted then set head to NULL and delete temp(free(temp)). • Step 8: If list contains multiple nodes, then check whether temp is the first node in the list (temp == head). • Step 9: If temp is the first node, then move the head to the next node (head = head → next), set head of previous to NULL (head → previous = NULL) and delete temp. • Step 10: If temp is not the first node, then check whether it is the last node in the list (temp → next == NULL). • Step 11: If temp is the last node then set temp of previous of next to NULL (temp → previous → next = NULL) and delete temp (free(temp)). • Step 12: If temp is not the first node and not the last node, then set temp of previous of next to temp of next (temp → previous → next = temp → next), temp of next of previous to temp of previous (temp → next → previous = temp → previous) and delete temp (free(temp)).
  • 63. Displaying a Double Linked List • We can use the following steps to display the elements of a double linked list... • Step 1: Check whether list is Empty (head == NULL) • Step 2: If it is Empty, then display 'List is Empty!!!' and terminate the function. • Step 3: If it is not Empty, then define a Node pointer 'temp’ and initialize with head. • Step 4: Display 'NULL <--- '. • Step 5: Keep displaying temp → data with an arrow (<===>) until temp reaches to the last node • Step 6: Finally, display temp → data with arrow pointing to NULL (temp → data ---> NULL).
  • 64. Application of Linked List •Large Numeric Arithmetic •Optimum Utilization of Memory Space •Represent Complex Structure – Tree, Graph

Editor's Notes

  1. Arrays take advantage of this “grid” structure to store lists of related information in adjacent memory locations to guarantee extreme efficiency for finding those values.
  2. Note: The name that you assign to this variable is very important because you will use it later in your code to access values and to modify the array.
  3. Note: I know that it seems strange at first to start counting from 0 instead of 1, but this is called Zero-Based Numbering. It’s very common in computer science.
  4. This is key because arrays are extremely efficient in accessing values because all the elements are stored in contiguous spaces in memory. This way, the computer knows exactly where to look to find the information you requested. But… there is a downside to it ? because this is not memory-efficient. You are reserving memory for future operations that may not occur. This is why arrays are recommended in situations when you know beforehand how many elements you are going to store.
  5. To insert into arrays, we move all the elements located to the right of the insertion site, one index to the right. Element “a” will now be at index 1, element “b” will be at index 2 and so on…
  6. What do you think will happen if the array is full and you try to insert an element? ?
  7. Remember when you delete a contact on your phone? Or an item on your computer documents section? They realign themselves automatically
  8. Note: Deletion is very efficient when you remove the last element. Since you need to create a variable to keep track of the last index that contains elements (in the diagram above, index 3), you can directly remove that element using the index.
  9. In Summary… Arrays are extremely powerful data structures that store elements of the same type. The type of elements and the size of the array are fixed and defined when you create it. Memory is allocated immediately after the array is created and it’s empty until you assign the values. Their elements are located in contiguous locations in memory, so they can be accessed very efficiently (random access, O(1) = constant time) using indices. Indices start at 0, not 1 like we are used to. Inserting elements at the beginning or in the middle of the array involves moving elements to the right. If the array is full, creating a new, larger array (which is not very efficient). Inserting at the end of the array is very efficient, constant time O(1). Removing elements from the beginning or from the middle of the array involves moving all the elements to the left to avoid leaving an empty space in memory. This guarantees that the elements are stored in contiguous spaces in memory. Removing at the end of the array is very efficient because you only delete the last element. To find an element, you need to check the entire array until you find it. If the data is sorted, you can use algorithms such as Binary Search to optimize the process.
  10. Single linked list is a sequence of elements in which every element has link to its next element in the sequence.
  11. #ijnclude<stdio.h> #include<conio.h> #include<stdlib.h>   void insertAtBeginning(int); //we create Node structure to create a memory block for data and reference/links struct Node { int data; struct Node *next; //C++ would be Node *next }*head = NULL;   void main() { // }
  12. void insertAtBeginning(int value) { struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = value; if(head == NULL) { newNode->next = NULL; head = newNode; } else { newNode->next = head; head = newNode; } printf("\nOne node inserted!!!\n"); }
  13. void insertAtEnd(int value) { struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = value; newNode->next = NULL; if(head == NULL) head = newNode; else { struct Node *temp = head; while(temp->next!= NULL) temp = temp->next; temp->next = newNode; } printf("\nOne node inserted!!!\n"); }
  14. void insertBetween(int value, int loc1, int loc2) { struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = value; if(head == NULL) { newNode->next = NULL; head = newNode; } else { struct Node *temp = head; while(temp->data != loc1 && temp->data != loc2) temp = temp->next; newNode->next = temp->next; temp->next = newNode; } printf("\nOne node inserted!!!\n"); }
  15. void removeBeginning() { if(head == NULL) printf("\n\nList is Empty!!!"); else { struct Node *temp = head; if(head->next == NULL) { head = NULL; free(temp); } else { head = temp->next; free(temp); printf("\nOne node deleted!!!\n\n"); } } }
  16. void removeEnd() { if(head == NULL) { printf("\nList is Empty!!!\n"); } else { struct Node *temp1 = head,*temp2; if(head->next == NULL) head = NULL; else { while(temp1->next != NULL) { temp2 = temp1; temp1 = temp1->next; } temp2->next = NULL; } free(temp1); printf("\nOne node deleted!!!\n\n"); } }
  17. void removeSpecific(int delValue) { struct Node *temp1 = head, *temp2; while(temp1->data != delValue) { if(temp1 -> next == NULL){ printf("\nGiven node not found in the list!!!"); goto functionEnd; } temp2 = temp1; temp1 = temp1 -> next; } temp2 -> next = temp1 -> next; free(temp1); printf("\nOne node deleted!!!\n\n"); functionEnd: }
  18. void removeSpecific(int delValue) { struct Node *temp1 = head, *temp2; while(temp1->data != delValue) { if(temp1 -> next == NULL){ printf("\nGiven node not found in the list!!!"); goto functionEnd; } temp2 = temp1; temp1 = temp1 -> next; } temp2 -> next = temp1 -> next; free(temp1); printf("\nOne node deleted!!!\n\n"); functionEnd: }
  19. void display() { if(head == NULL) { printf("\nList is Empty\n"); } else { struct Node *temp = head; printf("\n\nList elements are - \n"); while(temp->next != NULL) { printf("%d --->",temp->data); temp = temp->next; } printf("%d --->NULL",temp->data); } }
  20. #include<stdio.h> #include<conio.h>  void insertAtBeginning(int); struct Node{ int data; struct Node *next; }*head = NULL;  void main(){ // }
  21. void insertAtBeginning(int value){ struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode -> data = value; if(head == NULL) { head = newNode; newNode -> next = head; } else { struct Node *temp = head; while(temp -> next != head) temp = temp -> next; newNode -> next = head; head = newNode; temp -> next = head; } printf("\nInsertion success!!!");}
  22. void insertAtEnd(int value){ struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode -> data = value; if(head == NULL) { head = newNode; newNode -> next = head; } else { struct Node *temp = head; while(temp -> next != head) temp = temp -> next; temp -> next = newNode; newNode -> next = head; } printf("\nInsertion success!!!"); }
  23. void insertAfter(int value, int location){ struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode -> data = value; if(head == NULL) { head = newNode; newNode -> next = head; } else { struct Node *temp = head; while(temp -> data != location) { if(temp -> next == head) { printf("Given node is not found in the list!!!"); goto EndFunction; } else { temp = temp -> next; } } newNode -> next = temp -> next; temp -> next = newNode; printf("\nInsertion success!!!"); } EndFunction; }
  24. void insertAfter(int value, int location){ struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode -> data = value; if(head == NULL) { head = newNode; newNode -> next = head; } else { struct Node *temp = head; while(temp -> data != location) { if(temp -> next == head) { printf("Given node is not found in the list!!!"); goto EndFunction; } else { temp = temp -> next; } } newNode -> next = temp -> next; temp -> next = newNode; printf("\nInsertion success!!!"); } EndFunction; }
  25. void deleteBeginning(){ if(head == NULL) { printf("List is Empty!!! Deletion not possible!!!"); } else { struct Node *temp = head; if(temp -> next == head) { head = NULL; free(temp); } else{ head = head -> next; free(temp); } printf("\nDeletion success!!!"); } }
  26. void deleteEnd() { if(head == NULL) printf("List is Empty!!! Deletion not possible!!!"); } else { struct Node *temp1 = head, temp2; if(temp1 -> next == head) { head = NULL; free(temp1); } Else { while(temp1 -> next != head) { temp2 = temp1; temp1 = temp1 -> next; } temp2 -> next = head; free(temp1); } printf("\nDeletion success!!!"); } }
  27. void deleteSpecific(int delValue){ if(head == NULL) { printf("List is Empty!!! Deletion not possible!!!"); } else { struct Node *temp1 = head, temp2; while(temp1 -> data != delValue) { if(temp1 -> next == head) { printf("\nGiven node is not found in the list!!!"); goto FuctionEnd; } else { temp2 = temp1; temp1 = temp1 -> next; } } if(temp1 -> next == head){ head = NULL; free(temp1); } Else { if(temp1 == head) { temp2 = head; while(temp2 -> next != head) temp2 = temp2 -> next; head = head -> next; temp2 -> next = head; free(temp1); } else { if(temp1 -> next == head) { temp2 -> next = head; } else { temp2 -> next = temp1 -> next; } free(temp1); } } printf("\nDeletion success!!!"); } FuctionEnd: }
  28. void deleteSpecific(int delValue){ if(head == NULL) { printf("List is Empty!!! Deletion not possible!!!"); } else { struct Node *temp1 = head, temp2; while(temp1 -> data != delValue) { if(temp1 -> next == head) { printf("\nGiven node is not found in the list!!!"); goto FuctionEnd; } else { temp2 = temp1; temp1 = temp1 -> next; } } if(temp1 -> next == head){ head = NULL; free(temp1); } Else { if(temp1 == head) { temp2 = head; while(temp2 -> next != head) temp2 = temp2 -> next; head = head -> next; temp2 -> next = head; free(temp1); } else { if(temp1 -> next == head) { temp2 -> next = head; } else { temp2 -> next = temp1 -> next; } free(temp1); } } printf("\nDeletion success!!!"); } FuctionEnd: }
  29. void display(){ if(head == NULL) printf("\nList is Empty!!!"); } else { struct Node *temp = head; printf("\nList elements are: \n"); while(temp -> next != head) { printf("%d ---> ",temp -> data); } printf("%d ---> %d", temp -> data, head -> data); } }
  30. ☀ In double linked list, the first node must be always pointed by head. ☀ Always the previous field of the first node must be NULL. ☀ Always the next field of the last node must be NULL.
  31. #include<stdio.h> #include<conio.h>  void insertAtBeginning(int); struct Node{ int data; struct Node *previous, *next; }*head = NULL;  void main(){ // }
  32. void insertAtBeginning(int value){ struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode -> data = value; newNode -> previous = NULL; if(head == NULL) { newNode -> next = NULL; head = newNode; } else { newNode -> next = head; head = newNode; } printf("\nInsertion success!!!"); }
  33. void insertAtEnd(int value){ struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode -> data = value; newNode -> next = NULL; if(head == NULL) { newNode -> previous = NULL; head = newNode; } else { struct Node *temp = head; while(temp -> next != NULL) temp = temp -> next; temp -> next = newNode; newNode -> previous = temp; } printf("\nInsertion success!!!"); }
  34. void insertAfter(int value, int location){ struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode -> data = value; if(head == NULL) { newNode -> previous = newNode -> next = NULL; head = newNode; } else { struct Node *temp1 = head, temp2; while(temp1 -> data != location) { if(temp1 -> next == NULL) { printf("Given node is not found in the list!!!"); goto EndFunction; } else { temp1 = temp1 -> next; } } temp2 = temp1 -> next; temp1 -> next = newNode; newNode -> previous = temp1; newNode -> next = temp2; temp2 -> previous = newNode; printf("\nInsertion success!!!"); } EndFunction: }
  35. void insertAfter(int value, int location){ struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode -> data = value; if(head == NULL) { newNode -> previous = newNode -> next = NULL; head = newNode; } else { struct Node *temp1 = head, temp2; while(temp1 -> data != location) { if(temp1 -> next == NULL) { printf("Given node is not found in the list!!!"); goto EndFunction; } else { temp1 = temp1 -> next; } } temp2 = temp1 -> next; temp1 -> next = newNode; newNode -> previous = temp1; newNode -> next = temp2; temp2 -> previous = newNode; printf("\nInsertion success!!!"); } EndFunction: }
  36. void deleteBeginning(){ if(head == NULL) printf("List is Empty!!! Deletion not possible!!!"); } else { struct Node *temp = head; if(temp -> previous == temp -> next) { head = NULL; free(temp); } else{ head = temp -> next; head -> previous = NULL; free(temp); } printf("\nDeletion success!!!"); } }
  37. void deleteEnd(){ if(head == NULL) { printf("List is Empty!!! Deletion not possible!!!"); } else { struct Node *temp = head; if(temp -> previous == temp -> next) { head = NULL; free(temp); } else{ while(temp -> next != NULL) temp = temp -> next; temp -> previous -> next = NULL; free(temp); } printf("\nDeletion success!!!"); } B}
  38. void deleteSpecific(int delValue){ if(head == NULL) printf("List is Empty!!! Deletion not possible!!!"); else { struct Node *temp = head; while(temp -> data != delValue) { if(temp -> next == NULL) { printf("\nGiven node is not found in the list!!!"); goto FuctionEnd; } else { temp = temp -> next; } } if(temp == head) { head = NULL; free(temp); } else { temp -> previous -> next = temp -> next; free(temp); } printf("\nDeletion success!!!"); } FuctionEnd: }
  39. void deleteSpecific(int delValue){ if(head == NULL) printf("List is Empty!!! Deletion not possible!!!"); else { struct Node *temp = head; while(temp -> data != delValue) { if(temp -> next == NULL) { printf("\nGiven node is not found in the list!!!"); goto FuctionEnd; } else { temp = temp -> next; } } if(temp == head) { head = NULL; free(temp); } else { temp -> previous -> next = temp -> next; free(temp); } printf("\nDeletion success!!!"); } FuctionEnd: }
  40. void display(){ if(head == NULL) printf("\nList is Empty!!!"); else { struct Node *temp = head; printf("\nList elements are: \n"); printf("NULL <--- "); while(temp -> next != NULL) { printf("%d <===> ",temp -> data); } printf("%d ---> NULL", temp -> data);