declare

Array Of Linked Lists



Sharing buttons:

hello again in this video I will show

you how to how to create an array of

linked lists okay

so here I have this sister array so and

in each array I have a list so that was

that mean that mean in each cell in our

array is the head of the list so that's

mean a pointer to the list okay so let's

let's see how to declare and how to

manage it okay so at first here so I

have a structure in my that's structure

and the structure let's declare it at

first okay so this structure here so

that's structure so let's name it snowed

so here in this structure I have two

fields one here let's name it value

let's make it's just an integer int so

let's name it value all let's just name

it V as volume and I have the the

pointer of the next node okay so that's

node so that's a pointer so we write

start like that let's name it next so

that's that okay so that's how we can

declare it so so let's now let's now see

how to declare the array okay so if I

want for example if I want for example

to declare an array of integers I will

right so I am T in C language for

and that's the name of the array okay

and that's the size of the array but

here I want to declare an array of

pointer of node so so instead of all

right

yeah int so that's of the type so here

no it is a type okay so I just write

node because that's declared type and

since it's here we don't need to declare

a structures in array so we just need to

declare the pointers which has two right

so here I talked about C language so all

right start like that that means that

this is an array this is a pointer

pointed in this in structure in the type

on this time okay

so that's it that's how you can declare

an array of head of lists

okay so that's it home for example how

to how to add an element so let's let's

just write a a function for example odd

I'd known so here in this function so

when we were wondering and want to add

some structure a new node so we must

specify in which place so I would want

to enter it here or here or here or here

so we just we must send I that's the

index and so when we enter a structure

so we must specify the value so let's

send the value okay so the first thing

you declare are two pointers and one

and and - so the this is those are

punchers so we write star like that and

one and then - so the first thing so we

must

yes we must allocate one of them so n1

or let's write so allocate and one shall

we initiate the value of n1 so n1 so

here the value is it will this vowel

here and I make the next of n1 equal the

whole mouth okay so now I created this

this new element and I initiated so

let's let's now link it so here that's

the eye that's of the index for example

if this I equal three so I must enter

this new element here okay

so let's add its in the end of the list

okay so at first so here when we

declared this when the whole destructor

oh yes we declared the heads here so if

cheese so we have this array that is the

array if t I is equal ma

Mike in this case for example if I is

equal to I just make T I equal this and

you know okay

okay so that's let's continue here so

that's if that's else here so I have at

least at least one element in this list

for example if I is equal freakin so

here I just Travers I'm adjust Travers

until I get the last element which the

the next of this element is equal multi

so let's use a for loop so for so let's

use until so now qu is equal T I so

that's me if I is equal three

that's me near to equal this pointer

here and until next is different of

Maheu excuse me

let's continue here and and - next is

different of now and the step is n to

equal

an - next okay so that's how you can

traverse linkedlist use using for loop

okay so here we don't do anything we

just Traverse and when you finish this

loop so here that's me I find that and -

next is a comma now here for example

that's mean and - in this case if I is

equal three lets me n 2 is equal this

structure here 7 here I just make until

next

they call this note

listen unit okay so that's it that

simple how to to ensure to use an array

of linked lists okay so in the next

video I will explain deeply how to use

the for loop to traverse a linked list

okay so bye for now