0% found this document useful (0 votes)
2 views

Linked List

The document provides an overview of linked lists as a dynamic data structure in programming, detailing their creation, manipulation, and memory management. It includes examples of creating dynamic variables of different types, such as integers, vectors, and structures, using allocation and deallocation techniques. The document also explains the structure of nodes within a linked list and how to manage their values and connections.

Uploaded by

Zineb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Linked List

The document provides an overview of linked lists as a dynamic data structure in programming, detailing their creation, manipulation, and memory management. It includes examples of creating dynamic variables of different types, such as integers, vectors, and structures, using allocation and deallocation techniques. The document also explains the structure of nodes within a linked list and how to manage their values and connections.

Uploaded by

Zineb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

University – BLIDA1

Department: Mathematics

Algorithms and Data Structures


Linked list

LAOUICI.Z

1
Linked List : Dynamic variable

Static Dynamic variable


variable
• Declared in the “Variable“
section Created or deleted during
execution through pointers using
• The system automatically allocates memory allocation and
the necessary memory space for it deallocation primitives
at compilation time

• Its size remains fixed during the


execution of the algorithm or sub-
algorithm.
2
Linked List : Dynamic
variable

Syntax
Function Allocate:
name_pointer  Allocate() ;

Procedure Free :
Free(name_pointer) ;

3
Linked List : Creation of a dynamic variable of
integer type

Example 1

Type pinteger = pointer int ;


Variable P : pinteger ;
P
P  Allocate() ; @10

5
(*P) = 5 ;
@10
Free(P);
4
Linked List : Creation of a dynamic variable of
vector type
Example 2
Type Vec = array [20] real;
P
Type PVec = pointer Vec;
@2
Variable P : PVec ;
x: real; 6 4
P  Allocate() ;
@2
(*P)  6 ;

*(P+2)  4 ;
Free(P);
// Now the array no longer exists, we no longer have the right to manipulate5 *p
Linked List : Creation of a
Example 3 structure
We manipulate the structure with
Type Date = structure the primitives Aff_A, Aff_M, and Aff_J
J, M, A : int ; end through the pointer p
Type pDate = pointer Date;
Variable P : pDate ;
P
P  Allocate() ; @20
20 J
Aff_A(p, 2004); 1 M
Aff_M(p, 1); 2004 A
Aff_J(p, 20);
@20
Free(P); // The variable no longer exists. 6
Linked List

7
Linked List

Allocate only the Add and remove


necessary memory space data as needed

8
Linked List : Data structures

A linked list (LL) is a linear data structure composed of a set of


nodes chained together.

L
@M1 X E1 @M2 E2 @M3 E3
X
@M1 @M2 @M3
VAL Field Next Field

A node is a structure that contains at least two fields


Linked List : Data structures

A linked list (LL) is a linear data structure composed of a set of


nodes chained together.

L
E1 E2 E3
X
VAL Next
Field Field
Type Node = structure // Node is not a
VAL : typeqlq ; list
Next : * Node;
end ;
Type List = * Node ; // A pointer to a node of the list
Linked List : linked linear lists
Model

Reserve space for a Node and place its


P  Allocate() ;
address in p

Free(P); P
@
val Next

@
Delete the node pointed to by P (P is not deleted)
11
Linked List : linked linear lists
Model

P  Allocate() ;
P
Free(P);
val Next
6
Procedure Aff_Val:

Aff_val(p, 6);
Affect a value to the Val field of the
node pointed by P.

12
Linked List : linked linear lists
Model
P  Allocate(); P
Q
Free(P);
val Next val Next val Next
Aff_Val:
Aff_val(P, 6);
6 X
Procedure Aff_Next:

Aff_Next(P, Q); Affect an address to the Next field of


the node pointed by P

13
Linked List : linked linear lists
Model
P  Allocate() ;
P Q
Free(P);
val Next val Next val Next
Aff_val(P, 6);

Aff_Next(P, Q);
6 5 X
Function Val():
X  val(P);
Return the content of the field Val of
Aff_val(Q, val(P)-1); the node pointed by P

15
Linked List : linked linear lists
Model
P  Allocate() ;
P
Free(P); Q

val Next val Next val Next


Aff_val(P, 6);
Aff_Next(P, Q);
6 5 X
Aff_val(P, val(P)-1);
Function Next():
Return the content of the 'Next' field of
the node pointed by P.
Aff_Next(P, Next (Q));

16

You might also like