Transcripts
1. Overview of Queue: This session will
start for the Q. So Q is theoretical and
practical session on the laptop. So we'll see the program
will execute on the system. The different lectures,
different programs are there for the Q that is
writing the program, executing our queue using an
array in C and C plus plus, we will implement queue using an array in
C and C plus plus. Then lecture two is for writing
the program and executing implement or to
implement a queue using linked list in C language
and C plus plus. Then lecture three is to
implement the queue to write a program and execute for implementing you using
circular linked list. We'll see what a
circular linked list, how to implement a queue using
this circular linked list. So these all are different, different programs for the hues and these are very
important and these are also asked in your
interview, exam. Different, different
programs for the queue. So here I've explained you have executed in on the system, you will understand
in more detail. Then Lecture four is to write
a program and execute for implementing
circular queue using an array in C and C plus
four different parts. Part one and part two are there. In order to implement circular
queue using an array. Then Lecture six is for writing program and
executing the dQ. We'll see also what
is DQ and we'll implement using
this or culinary. We see what a circular area then what is DQ and how to implement the queue using circular area in C language and C plus plus. Then in lecture seven, there will be proved Writing
Program and executed execution of privacy or
this priority queue. Then we'll implement
a priority queue using the linked list in C and C plus plus we write a program will execute
on the system.
2. Queue using array Session1Lecture1: Start writing the program and execute it for Windows
operating system. Or that the prerequisite
which is required is that you need to install
the code not ideal. It's very easy to install. You just download
the code block ID, which is freely available
and you install it. Once you install it, just
double-click on it and you will this screen on your
operating system. On your system, you will
get this screen that is, you just create a new project by going to the File and
then New Project. This manner, if you see here. And once you do then click on Console Application,
click on Next. And then here we will be seeing the program in C plus plus
language as well as see. So here, I will start with first the C plus plus C
plus plus language. Then I will start to see. So I'm already created the
new project just to show you, I'm just showing in this manner. I'm showing you here. Just click on C
plus plus months, you click on cplusplus, you are, you will give the
name of the folder. You want to read this project, and then click on Next. This is how you will
create a project. If you wanted to create what? C plus plus. So I have already created
the project and program. This is a main function. So when you execute your
C plus plus program, the control comes in this very first function
that is main function. And line-by-line, these
instructions will be executed from
your main function. Now it's a C plus plus
programs will have created a class here by name QFD IMP l, that is the shortening of
IPM, its implementation. You can give any meaningful
name here of your class. This class it is having, first of all, an instructor. Then it is having a
virtual destructor. You can see here. Then these
are the functions which we'll be using in my plots. The queue, insert Q, delete, explain then these two
conditions into empty and is careful to check
whether the queue is empty or the queue
is full or not. Whenever B and then
delete these functions, these conditions we have to check reporting, so
adding and deleting. So I will I will explain
you in detail further. These, if you'd see these
functions which are there, these are all under the
public access specifiers. So have made these
member functions as public constructor, destructor and the functions, I mean it's public
in this class. And what our private in the
private access by specifying, put these member variables. So since we know
that in case of dq, first of all, just
let me open though. Note here, yeah, in the
implementation of using area. So you can see here, I
have used this at a, this is just an
example to show you, you know, in case of
the edit, first of all, if elements are placed
in the main remedy in sequential order and the location on one
after the other. So here, if you see here this indexing is starting
from 0 to n minus one. So depending upon what
is the size of the eddy, You mentioned that much
memory will be allocated. And these are elements
which are there. Here. We know that for
support in case of the Q, Q Searching is
happening at one end. So as I told you that
insertion will happen. This is the red and deletion happens and the other
end that other lenders, that is the frontend. We have seen all the
things photonic wires, so each any faster upon. If you just compare with that
on both stack and stack, we have used only one event. We implemented the
stack using edit, be used only in that case. Since by your views
only one variable. Because in case of
the stack though, insertion and deletion, that means the push and
pop operation. That either the
equivalent to push and pop it in this scene and told me all these operations are happening in
case of this tech, therefore, only one
variable most required. In the case of the cube neon, we are implementing that
unions and getting. So first of all, we know that insertion deletion is happening and
definitive treatment. So there are two
videos are required. Initially these front-end,
which is there, We'll, we'll initialize
it as minus one. Once we insert,
actually, as I told you, whenever we insert will
be inserting other error. Whenever we believe
we'll delete and pencil, then literally you don't consider these
elements and initially just consider the front end
bread will be minus one. And this is not true. You are having an empty queue. That is, these elements are
not build just a while loop. This thing actually. So in that case what happens? So just let me move here. If you just see here I just
opened a notepad initially, what happens first of all, your practice minus one and
the red is also minus one. Let me just queue is empty. Now, you want to do the operations of insertion
patient on collision. So you have the interview
required in case of insertion. So this is your
insertion or deletion. And in an insertion,
men is empty. This is the region. In this case when. Is empty, that is minus one. So in this case,
what will happen? What you will do, you
will increment by one. So you will do plus plus. And although you will do plus, plus these operations,
you will be for farming. And then you will be simply since inception
happens and that I'd met an area which
you have created, you will simply an
index on this day, you will simply store
the element with using one to insert your name, though at a slightly skew. If you'll give the subscript and then you will
lose like this, red is equal to the item
which users want to insert. Since I told you that
insertion happens at this and deletions
happen at the front end. So we are not using
girlfriend. You're using rare. At this. We have already done this part. Just remember when you insert, you have to always deal with
this variable red menu, have to deal with
this gunk variables when you are inserting on me. If you've taken at your
front is minus one, that means your queue is empty. In that case, very
first time you have to implement the threatened. If you have done
this, not minus one, that means your
queue is not empty. So in that case,
you don't need to deal with this variable. You are concerned with this. They're variable on the end, you will do this operation. So all these things we will
be doing in our program. So I hope you
understood the thing. In case on the deletion, mortars, doping case,
somebody deletion. Whenever you perform
the deletion, you will deal with them. First of all,
whenever you insert, you have to invest false check whether it is having space, then only you can insert that
conditionally or protect. So we will see how the
object in our program, while deletion, you have to
check whether your instances. If you're curious, emptied, that means you cannot delete
it. The queue is empty. There is no question of elements will be present
if the QSR for you, there is no question on
deleting these things. You have to check when you perform insertion and deletion. That is in case of insertion, you have to check whether
the queue is full or not if you cannot insert. And in case of
denaturing a project where the queue is empty or not. If it is empty, you cannot delete these things
you are required. So in case of the deletion, what happens in case
of the deletion? First of all, you will,
you want to delete. So before deleting, you
simply you want to return the item which users
will be believing. First you will collect. Video was all humans
simply this year. In this manner, you're adding. Then subscript. Like this. Here you will
use item is important. That means this Planet Index, whatever element is stored in
this video, but this item, and then you will send
me leu plus, plus. You will simply
did on this item. Deletion happens
at the plankton. These operations you have to both phones in
case on the queue. Now, moving to the program
itself, Let's see. So first of all, what
operations are there for the q? These are the operations
that is I have named by q insert, that is what? Inserting an element
in the queue, you're ready to delete, deliberate in the
queue and return the element index of that, not at the index of
the display that, that means that will display
on the elements which are present in the few examples. Just moving to this diagram,
unconsidered this q. Suppose you are done with
insertion and deletion. And finally, you
having the front, just having the index that is 0 and that air is
having the index fine. Suppose the size of the six. So if the size of the queue
is six, therefore total, how much elements you
can fill six elements, therefore, the indexing
starts from 0 to five. And you can see here
on the elements are filled and therefore, please having this day
index on the last element, whereas you against fantasy. Now if you perform the
bleaching operation, since I told you that
deletion happens on the other plankton
and not that the reader. In that case, what
will happen if you, if you are deleting the element so far as to call this one also, we know that this plant in this situation in this example, is having the index
0 so that one will be deleted in front,
should be incremented. So first of all, one
you should return, you should explode
it and some medium, you have to implement. Frank, so what will
happen in that case? This one will be deleted. And if you see here beauty here, simply return the
element which was present actually got
incremented by one. So indexes one. What is the element
isn't weather. And the index of the
parent, he is present. Now, here again, if you want
to delete the element again, what the addition since happens on near the front
end not at the reading. For this, what you
will do again, you will simply return this three and you will
increment by one. So then what will happen in
here if you'd see that now the completed gun by element which was
president at index, one, that is at the front index and then you
have incremented by one. So now front is equal to tone and the sixth
element is present. Now you can see here, this is your array of this
size that is six elements. If you haven't given the size. And you can see
here that index 01, the more elements or prison. Therefore, you
know that this red is having the depths
of the last element, that is this much
so if you want to insert any element and
also what I'm teaching, you have to check, first of all, mineral than before
inserting any animal. You have to check whether
the queue is full or not. If the queue is full,
then you cannot insert. What is that condition
to check whether or not in that condition is that infrared is equal
to max minus one. What is max? Maximum will
be the total size of your size of the array is
six, that will be the max. So six minus one,
that is simply fight. You will check whether
the red is equivocal. It is, if it is
having this pipe, then further in
social you cannot, cannot happen because your app is having the index
of the last element. So in that case, you
will simply give the message error
message that you cannot insert because
your queue is full. You can see here what decides actually whether
your queue is full or not. This red position,
if the read is having the index on
the last animate, then you decide whether
you are useful or not. So if you see here
in this condition, in this case that rare is having the index on the
last element. That is fine. You can see here
that you are having an index 0 and at index one, you can see here there
is no element present. You are having this space to insert more poorly
administrators are two elements, but since Sadat is deciding whether you
can insert or not, it is saying that
you cannot insert because you can see here
red is equal to five, that is the index on
the last elements. So therefore you cannot perform the search and this is
in case of the area. So this this is a decided
disadvantage in the Q&A. If you implement security
of thing, Eddie, you can see here that term beside you are having the
space since you can still, you cannot insert
any element because your air is having the
index of the last element. What about if you are having
the q of the largest size? That is, if you are
having the area on the largest size in that case. In that case, you can understand
how much there will be only state of memory
depending upon your trend, whether if your friend
is having the index on not having the
value, that is cool. So you can see
here, in this case, plant is equal to
two and the element that is present is six. Suppose your practice
is not this, these two elements
are not there. So parenthesis, having
the index legs forward, that is, the element is in SQL. In that case for
space will be wasted. What about those eyes? Are the cues very huge? In that case, you
can understand this by having the index of
the second last element. So how much wastage of
memory will be dealt? Specifically, we're
having so much space. Similar you are not
able to utilize because your ad is having the
index of the last element. So this is how this is
a great disadvantage. Certain market in case of if you implement the queue
using an array. So this is just to show you
what problems can occur. So in this case how to
overcome with the center. You can either shift
all these elements onto the left side. And it also therefore six. Chipped all these elements
with an F site and then edges front and smell is
rare accordingly. So in that case, but you can simply, you realize space
but in the area. But the problem is
that overhead will be that up shifting all the
elements onto the left side. So that is an overhead. So we will not go
to this approach. So another thing is that
you can simply use the look you moving through the program, that is through
the project here. These are the
operations as I told you display and therefore row. Then this is PMT and SQL pool. If we are using SQL
and SQL pool before, when you will check a few empty, whenever you are simply on
to delete any elements. So you have to check whether the cues and the queue is empty. You cannot delete any
animal menu and check this condition coupons skillful when we want to
insert any element. These are the
private data members that is doctrines and rare. We know that at the
front end we are simply deleting the element
as simply inserting the name of the queue
using bear a is q and the underscore array and this subscript maximum,
what is this max? So max I have defined as
the size of the queue. Since we had implementing queue using arrays or the size I have defined as net for public, I've elements only I can insert, I cannot insert more than that. So that thing we have to check whenever we perform
insertion and deletion. So let's move on to the main
function now we have seen what now what the class will
have the dispute edit bill MBI, MPL. And let's move on to
the main function here. Therefore, this is
your main function, that is the entry point and you execute your program
control comes here. And the very first
time, we are displaying the message on the
console program to implement a queue
using an array. And these are the variables
which are declared. So we will see what is the
use this first of all, an option and I did. Here we will see what
is the use of bit and the next variable is
a name of the class. If you see here, you'd
see here your area, MTL, it is a name of the class. It is present. And you are creating a static
object that is QFD, name of the class Q&A I MPLS. Which class is this one? The glass which you
are defining here. This one, the glass Q and M. No-one. You are having the class and all the member functions
and the member variables. You are creating an object. Now. You're creating the object
of this because we will call different functions of insertion and deletion by this object. So this is a C Plus Plus language and therefore
you're creating a class and you then you are creating
the static object in the main function and lead
static objects that you will, all the different functions
of insertion and reagent. Now what we are doing, they're using one, we are
using an infinite loop. We will give the user of different options like
abuser of press one. That means your
users onto insert a user wanted to delete user
is supposed to press two. If you don't want to
poke on peak ovulation, user onto, user should see
supposed to press three. It will display all
the elements and peculiar they're
supposed to end up poor. And before user is supposed to eggs in one to exit and uses
supposed to enter five. So these things
we are providing, these options are available and accordingly we are asking the
user to enter the options. You can give any options. And if he was a good one, that means you want to insert any uneven user is supposed
to then enter the lumen, which user one to
insert in the queue. And if I want to delete, then use an address. And therefore that
you can know that for insertion there are
different operation for division narrative can
operation copying, there is a pitcher and so on. Therefore, we are using the switch case That will
ask the user to enter the option depending
upon if user to enter two then division
operation and perform the code. I have taken a
switch case, cases, case one of users press
Enter an option as one. In that case, what you do is usable form the
insertion operator. So in this case, one wouldn't be executed and these instructions
wouldn't be executed. And entry user enter t2. Then in this case, two will be executed
because option is true. And then these
instructions that will be executed if user
enter simply three, in that case the
oxygen is three, therefore this instruction
will be executed. And if this, suppose
the users whose users, and therefore it in that cases, case for millet be execute this satisfied and this
instruction will be executed. So this is how we're
different options, different operations
can be performed. Therefore, we are using
switch court case and why we're using
this vitamin. So that if the user wants to insert an element, suppose one, if you don't use this
vitamin, in that case, only one operation can
be for formatter time. So you want this loop
to go on running till the user don't
exhibit user enter five. That means uterus want to exit. This thing also we will
provide to the users. Of course, you'd assume there is a reason we are using
the infinite loop. And these options will
keep on coming to the, onto the console so that the melanin misuse
or don't get five, that means you don't want to exit user to understand
perform operation. So that is a reason
we are using while. But suppose the user enter five, dampen this case phi will be
executed and we will exit. So it says that
this has measure. Your while loop will read. Your control comes
out of the room. This case fine. If the user wants to exit, user will enter five months
and each of this execution, when it takes place
instruction that is exit one, you will be exempted
from your program. These are different options. Now let us see actually if
you don't want to insert that put option will be
one user enter one option, one will be there, there is switch option
on that one case one will be executed
is so that means the user want to
insert any material displaying this message
CL enter the elements. When suddenly the Curia
asking user to enter the human user will enter any element in the
you and the users. Whatever user enters item we'll collect in
this variable item. What is this item
on the datatype? Items of datatype integer here, because I was indeed user entertained element
is of type integer using the full 40 element for E value that is on
the datatype integer. So that when selecting
this variable there is this function that is q. Insert how
you will call this, you insert it since
we have already created this Q edit objects, static object, we
have created here. By this object, you can simply
call its member function. So therefore T here, this queue insert
we're calling when there's few edits and we
are passing this item. So in this function to perform the operation of inserting
this item in the queue. Suppose user and not one. In that case, this case
two will be executed and you add a dot, you delete. That means this instruction and the executive deafness
user options for what you have already written the two means the user wanted
to delete any element. Therefore, you
will simply follow the delete function by this
static object in this manner. And we know that when you're
deleting any element, the item will be return. And then you are supposed
stool beside them will be written and this message will be deleted item this
value, which is return. When you are printing this on consoles to this operation
will be order deletions. If the user give this three, that means the peak value. So that means the user wants
to perform the operation, you include it on
the peak value. If they use a gift for this
option for is for display. The elements present in the
kiln that for this case, four will be executed
in this manner. And this loaded
calling the display function by this static object. This display, we'll
see what coding is there in order to display
all learning moments. And then this case file, which is that it
is for exhibiting. If you want to exit the program, then you simply write
in case five exec mode. And then the default one, you have empty user donor
and turning this 12345, that means another
things whatever usually interpreted PDA gamma
under this defaults, this condition
will be satisfied. And this message, when
you've finished it on pencil diffuser lunar into 12345 years and any other
value in that cases, DePaul will be satisfying.
3. Queue using array Session1Lecture2: And let us see one-by-one
once you insert what, what is the definition of it? Now if you just don't
want to insult, this is my function of the queue insert in C
plus plus language. But since I'm defining this few Insert function
outside the plots, what I'm giving the name of the class scope resolution and then the name
of the function. Here. This hue insert means whatever item user
have fast here in this function within this item will be some p inserted
into the queue. And therefore, since therefore this item you have thought
inserting your kids, Though you what paints are
required when you insert any uneven and let you check whether your queue
is full or not. That means this message will be printed queue overflow
condition and so item cannot be inserted in document then this handled
it is a last night. This message, what
is it skillful? That means men will
be the queue full. Happen as I told you, if there'll be
underneath the case when Red Hat average the
size of the eddy, that is, your Q will be. That is the condition.
So let us see what this pupil is having. If you see here this cupful is, it is also undefined outside of class or polymorphic
class and then spoke region and
then the name of the function and
how it is defined. It is having these instructions. What does this
instruction if there is equal to max minus one, if it reaches to the mx
minus one, so here it is. In reaching there. That means you are simply returning one. That means your q is false. If this is not my x minus one, that means you are having some other index off some other element and
not the last element. Therefore, in that
case you can see the details will
be there deficits. That case it's
going to return 0. So it means that Q is not full. For this condition,
you have to check whether queue is full or
not before inserting it. Therefore, if this
condition is not satisfied, and therefore you,
this instruction does not get executed. Therefore, you are other
instructions get executed. Let me say a queue is not full. You have to check. As I told you, the adult self, you have demand you
and one to perform the insertion operation so that bill first of all
happen at the end. So first of all, you
have to check whether your practice minus
one plus minus one. That means here Q is empty. So in that case
you will increment the front fenders agreement. Meaning preventing read. You will also include the
parentheses minus one, so that only friend
is minus one. If I increment the front by one, that means minus one plus
one becomes 0 is equal to 0. Then since the insertion
happens in the dead end, and this will happen. If you see here what I've done. And then I had inserted
element and this, and this index of this
array into a dispute. This, if you see here
what this line means, this line, if you see
here the name on the EDI. First of all, we
will increment first the red and then that index. We will be simply storing
the new elements. So this nine is equivalent
to say that the first is this incrementing q. And those code, simply item. This instruction will be executed only when you can
insert when your queue is not full status their space in your queue then
only you can insert and you will increment
the read index. You will simply store
this item because we know that insertion
happens at the end and not at the fact that
these things are required when you simply insert. The next thing which
is required is that when you delete actually, so as I told you believe
happens at front-end, that n different by this
object and calling this Q DDS. And therefore it
will returns items. Item is on the datatype. It you'll see here
this item is off the datatype that is integer. Moving to the function
definition that is skewed in it. You know that what we are
supposed to do, this function, whenever you want to
delete any element, you have to first ensure whether your queue is empty or not. Because if the queue is empty, there is no question of
elements to be pleasant. Therefore, you cannot perform the religion operation because
no animate is present. Therefore, this
condition, you have to check what is condition
will be there for the QFD. The condition will be forced upon when your
parent is equal to, equal to minus one. Let me so Q is empty when
Trump is equal to plus one. That means support the CEO. So you can see
that in this case, what bit and what is happening your practice having
the index status three, that is having the index data
students, so it is less. Hi everyone. As with as you compare
with that of me, Frank. Therefore, you can see here q is everything
because you know that whenever practice having
the index parameter would have the index of 0. That means if you
perform the deletion, deletion happens
at the front end. Therefore, this will mean return and human would
have return from 0, the index and this friend
would have incremented. Again the same thing if
you perform the relief. This item will be return and this trend will be incremented. Again, the same thing. That is, if you want
to delete this item, this item would have been return and firm would
have implemented. This is how you can see now the queue is
empty when there is a cubic uncertainty
when current is equal to simply plus one. In that case, the
queue is empty, so it's traditionally I've checked in the
front is minus one. We know that the current
is minus one because usually the front rows
minus one, right? That means your queue is empty. This is one condition. Another condition is that if the plant is equal to plus one, that means you can
see here the plant is called a tree and it
ended at is equal to, you can see here the stool is equal to simply
read plus one. This is condition will be
satisfied and therefore your, you can ensure that
your queue is empty. Therefore, you've
been return here one. If this condition
gets satisfied, then you will simply return
one as you will return 0. This is the condition. When you perform delete, you have to perform check. First of all, the
queue is empty or not. If the queue is empty,
then you will write this condition message
on the console Q undertook condition and
so item cannot be deleted. This thing is required
and then false bleeding. What as I told you how to
perform the deletion operation, first of all, you'll
return the item so the skew area and then
front you can see here. Then you are supposed to simply, in whatever element is there, you will secrete it
and then you will increment the count by one. This thing which is there. You can simply
return to edit run. You can simply write as
simply you can write w1 is equal to Look,
you underscore. You will simply
write it like this. You underscored. And this front you
will post support, save the item in some videos. And I've been saving, then
you will write plus plus. That means we will
increment by one. And here you can see bone, this item, this,
these three lines, I've returned in
this single line. So depending upon
written in this line, so depending upon you can simply either
write in this manner, you can simply write
enough single nine. So this is how you poke on, but this is how deletion
happens in case on the other functions
which are there. If you see here, you are calling insertion York,
calling deletion, then whatever item
return you are simply messaging your in
your, in your console. Then the big thing
then you'll simply calling the function value is what I told you what will be the definition
of the function? First of all, you have to
see whether you're curious and you are not simply you will call this
function already. You will have defined
this function that VMT ventral
root is minus one, then it will be empty. Or when trying to say equal to red plus one, then
it will be empty. So whatever conditions satisfy
any of them is satisfied, that means that U is empty, and therefore you cannot
return any value. The queue is empty if this
condition is not satisfied, therefore, this exit
will also not happen. Therefore directly
this instruction will be executed as return. You underscore add a
and the subscript. That means you are
said to simply returning the element index. That is the thing in
case of the beak. Now, the next message, the next message you
give display waters. The display function here. In case of the switch kids
is a state function you are simply calling here in this, by this tactic objects, so this display function. So what is the logic? First of all, you are Protect whether your queue
is empty or not. If the queue is empty, obviously you are not. You cannot display any elements. Render queue is empty. Then this few or no pill
condition will happen and you will accept a
queue is not empty. In that case, this for-loop, since you want to display
all the elements. So how will display all the elements in leaders
going through this, you'll see here this, let me just consider this
example in Michigan. See here that you
will display it. So this is your Q, and this is where the plant is
having their next joule, and the sixth is pleasant and red is having
the index five. And this five is
element is present. If you wanted to split these
elements of the queue. You cannot start from the
index 0 to n minus one because no elements or
President index us 01, therefore vary from
value will start. You can see here that your
elements starts from the index that is stranded is
equal to two and it tends to the n. Therefore, you will start your index
from Grant and you will increment it and
then you reach here. So that means you can
see here that Isaac, while you are
starting from there, you are adding the condition
if id distorted it, the less or equal to that, then you are simply
doing I plus plus. So network. You would simply write them the name on the QFD
and then subscript I. You know, you will be
putting these values. Therefore front will
be in this case, the front becomes equal to
two network for ice equal to, to recompute area a subscript
to simply displaying. It can only when it is
six you are displaying. Then again, this
for-loop repeats I gets incremented by one. Therefore, you can have
aluminum present here. And therefore you can
see I less or equal to you did you don't
reach and this index, it doesn't simply miscellaneous
printing this subscript, the I means these
values one by one. That is all the aluminum. The 691215 will be printed because you
started from trunk and you end up so you
understood this value. This is how you will display
the elements of your cube. Now the next thing
is their exhibit. That is fine. What is this case?
Five will be executed and therefore, this exhibit one, that is this proton
will get come to the end whenever you
use one to exit, users simply enter five, that means user door to
exit from the program. Therefore, you will come
out of this loop also. And this is how
this human protein. Then if somebody quality invalid condition that
isn't user enter any value, then it will be an
embedded condition. Now, this is how
this switch case which we have seen the program temperament the queue
using the wood. These are the
different, different, such case we have seen on
display now and then returns, you know, I hope so. I have covered each and
every function here. So you understood this, what we are doing in the
C plus plus program. First of all, we
are including this, in this manner is
iostream and all these header file stdio.h
edge then lived out edge. And this has defined max by volume defining
this Maxwell pipe. Because I will, when
I create a queue, I will give this size of
which is required to implant, that is the size of the queue. Whatever value you give. That value will
definitely you can use as a size of the
queue using them. Adding this namespace std, then this name of the class and the constructor definition
friend is minus one, right? Is minus one. Then these
functions which are there, you insert you to leave. So on these of functions
we have seen here. Now, let's compile. The program, will then run. You can see an
unjust compiled and executed it so there are
no errors and then gone. And if they haven't
been this output EXE. Now, you can see here, you can see I'm
getting this message programmed to
implement the queue using one-point
social for deletions, report, peak, full
point display Piper, exit and enter the option. Suppose user onto an insert, user entered option
as much, one is fine. So therefore it will ask me, I have asked user entered an event to be inserted
in that you will ask user to enter
the lumen which is on to insert it in the ICU. So I Vendor ten.
Therefore, again, I'm entering one
that is foreign, so deconstructing
the elements are 40. Again, I do. If I want to display the
elements in the queue, I will portfolios for display, I will enter false. Therefore, you can see here
element is an element, this party, you can see here. There's no spacing is n ten. Therefore, you bought like this element is
ten element this. And if you want to
delete and you will simply enter two for deletion. Therefore, you can see
delete deleted item. If you want to release, then you will simply enter two you can see and deleted item is t, which is present. Again, you phone,
you enter the option is you can see here
you have delete, deleted all the levels. Level. Finally, when you became empty again,
you are deleting. Then it says q under
flow condition and so item cannot be
deleted from the queue. Again, this message on
the queue saying that Underflow condition there
is no element isn't in the queue and the borders are fortunate deleting
any and emitted. So these are the
things which you have to keep into mind.
I'm just enter. So this is how we have seen the program board room implementing the queue using Eddy in C plus plus language. And we will also see for the
C language the same program, but in the C language, only difference will be
the syntax difference. There is in C plus
plus it is represented in different manner
and see language, it doesn't depend
different Minnesota. So now I have already
created a project down since we have seen in
earlier in this session. How to create a project, we have to simply click
on file in this manner. Then we have to
simply click on new. We have to simply click
on New Project and then click on Console
Application going next. And then we will
simply selecting the C and then you'll
be writing the next. This is how you have to
complete a project folder. If you want to write the
program in the C language. I already have created. I have written this lines of
the code in this function. Let us may not see. Now what is required here. We can see first of all, in case of the C19 ridge, we are not using the class. You're not using
since nC language, the classes not required, you're not using whoops concepts
and therefore we're not creating any static
object directly. You can see here we are having the functions and the
video business here. This is the name on the Adi. This isn't, this is
a name of the queue using the EDI and these
variables that strand, which is initialized
to minus one. And then this function, this, these are all the functions
instance which I will be between the English will be defining what is the difference in grading it in the C language and C plus, plus almost all the lines of instructions with
the US involved. C language and C plus plus they are same on
either difference in nursing Texans and C language
are not using the class. We're not creating
a static object. Therefore, directly we have
to write in this manner. Therefore, all the
functions and on the member variables
are present globally. Now in this main function, if you execute the program
control comes here. Line-by-line instructions
get executed. Therefore, it says program to implement a queue using EDI. Again, the same thing you are using a while loop,
infinite loop. And you are this switch case, thing that Amino that
the switch case, that means user will
keep on entering these different
different options and user will get
these different, different operations to be performed if he
doesn't want to exit. This is going to exit from the while loop by simply
giving this option is filed and this control comes out of this
loop pairs infinite. Now, same thing
that you may abuse. So that is the functions which are there is
like insertion. So if you're seeing your
insertion, insert any elements. So how you will
let us move on to the main function so that you can understand
it more butter. In the main function. First of all, this is dependent
on options to the user. Enter case one, this
thing will be executed, in this case it using demand. That means you want to poke
on the insertion operation. Therefore directly you can
see since it says C language, the programming language,
therefore let us know. We have not created any class, we have not created any
static object directly. We are calling the insert
function here in this manner. Therefore, if you see here, the definition of
insert is like this. We first of all, before
inserting even check in vacuous, fuller NORC, Epicurus,
full deafness. You cannot insert, you have to accept the queue is not full. That means you can
vote on in searching and that we will check if
the current is minus one. You will implement
it and you will do. It's the same
instructions of quoting, even in case of the
deleting any aluminum. That is from the main function. You can see here in
the main function in the user enter two then until each element perform what we are supposed to do,
deletion operation. First of all, we'll check if
the queue is empty or not. If the queue is not empty, you can simply delete
any element that you accepted at mu
and human person. But if this condition is not
satisfied, million would. In that case, we will simply return the front element and the front index and we
will increment the month. So this is how we will
do that is returning to underscore that and
then I plus, plus. This is, this is how to delete any element
from the queue. Then what about the options
like the monkeys three, that is a peak value. What we're supposed to
do in the peak value, or we have to first check
whether the quiz empty or not. Epicurus not empty,
wherein you can simply queue is not empty, then this condition
will be not satisfied. That means then you can simply return the element president, the front index there for the name of the Q1
was good at it. And then this front
index in the subscript. Then another thing
is that if you want to display the element, then you would use a
milk if this option is food and therefore
their display, this instruction will be executed as you don't
want to display the elements near the same thing as you'd have to check first,
the queue is empty or not. If it is empty, you
can own display. And if not empty, then this for loop I is equal to
one I less than equity. As we have seen that how we will display the
elements of the queue, we will start from the elements of the plank index will start from data Newell and Tilda x. So there is a reason we
have given in this manner. I is equal to front. We started from, from in this condition and then
I plus plus and we are printing this mandate is queue name on the Q underscore
ID and then subscript. That is one by one, we
will be print on printing the elements from
index two, index. This is how the display our vision
and then finally views it enter quite simply, there was a real call,
the exit and the user uncontrolled comes
out on this song. Means a program gets executed. An exhibit. In this case, you
don't want to enter any other options and default
the user enter wrong, then this message will be
printed as invalid option. This is how the same
thing is there and poke you Foodland QM, EPOC here. This is also the same that if that is equal to max minus one, therefore, it will return one. That means your q is full
bandwidth that you will be pulling whenever this is
equal to max minus one. Then in case of q empty
when we empty move and simply parenthesis
minus one or from physical will be empty. It's an operation
like insertion, deletion and then
fecal operations display all these things we
have seen a let us compile the program will compile
the burn pile you can see and then organiza lead
and then build and run. Again. Here we are agreeing used
in using the C language. So if user enter one, again, the same message programmed to implement the queue using EDI, I'll get into user insertion should have been there
for the element. And again, you give, you will give the element with user1 to insert in the
queue, that is 20. Again, you want to insert,
you will write one. Again, I get 14. Again, I give interruption
again, I hit 74. Actually that means displays. So it will, you
can see at 204070, all these elements
were displayed which you have simply inserted. Not you want to delete, you will enter your lender. Do you get them to
be deleted as 20? So therefore, if you will again perform
deletion of patient, and again this 40
will be deleted. So this is how the
deletion happens. First of all, if you give four in the display only elements
seventies President, again, you invertible, that
means again you enter. Therefore, under
the switch case, we have given different
operands and it says home, you've seen execution and
C language, all sources. Now I'm done for this session in which
we had simply seen, we have started
just quickly device what we have seen
now about the Q, the basics, very quickly we have moved and then we started writing the program to implement the queue
using the array. And we have also executed it. We have written this program in C language as well
as well as in C plus plus for Windows operating
system intuited it. Let's meet in the next
session where we will be implementing the queue
using the linked list in C language and C plus plus or this possession was
accompanied knee or implementing the
queue using an array in C and C plus plus
other session I'll be covering to write a
program and executing to implement a queue using a linked list in C
language and steepness. Let's meet in the
next session on now. Bye, bye, Take care. Thanks a lot.
4. Queue using Linked Lists Session2Lecture1: Hi, welcome to the
new session of writing the program
and executing for implementing the queue using linked list in C
language as C plus plus. For Windows operating system. We will be using the code block ID in order to write the
program and execute. And we will be writing in C language as well
as C plus plus. So this complementation
of the cube will be using the linked list. In an earlier session,
we have written the program and executed for
Windows operating system. And we have implemented
that you like using EDI and this session is
using up inked list. I have also explained
you VFC and outputting audio
session using the edit. We have also seen what
problems can happen. Implement the queue
using the edit. What other disadvantages? Now you can decide what you
have to use accordingly, you can simply write a program to implement you're using area, or you can simply go through the session
and you can break your program implementing the
queue using a LinkedList. I mean, all the
basics of the QT till now we have seen what SQL
just quickly devising you. First of all, in the queue, the insertion
deletion happens at the end status at
the different ends. Here we are referring
that the place where the insertion happens in
the queue item, one end, that is the read end in case of q and the
deletion operation, which happens the
queue at the other end that we name and we have
named it as a ranking. So it will be heavily
also seen that dark, it obeys the roulette
is first-in, first-out it is the element
which will be inserted, workforce will be
deleted very posts, the lumen which is inserted, lives will be lost. So that is the reason
first-in, first-out. So now just weakly moving to code block ID made in getting the program
and it will be executing. So far as to a
folder prerequisite required here is that you
need to download the code, block it, and you
need to install it. We have, as I mentioned, it's called loci these
freely available, it's very easy to
download and install it. You can find the steps on
in your room, in Google, you can Google how to
install this board blog ID. And then let's write
a program with me. Let's see the program
and let's execute it. Now moving through
the code block ID, and I've already created
a new project in the code block ID
for C plus plus or your voice will be seeing the program in C plus plus
language will execute it, and then the programming
language and we will be executing this predict the after creating the project
them I have created here. First of all, the class name. That is first of
all in C plus plus, we know that you
will be the classes, then you how to
access the members. We have to create an object to access these members from outside of the class.
Suppose, let's see. I have defined the class
that is by the name, that this is the name of
the class skew linked list. And I underscored I
unpeel it reports to implementation
supposed to appoint. This is the class and what
is there in the class, if you see here in this glass, I'm having the private and
public access a specifier, but in public what
I had made his public and neither
constructed as public. I haven't needed the destructor, some oblique and I have
made all the functions which we'll be using what the
queue as a public hearing. So to insert the
element in the QQ, this constructor
then the destructor made his public then
to insert to insert the limited the Q-Q
deleted believed element. And that will
return the value of the cube display to display all elements of the nodes
in the linked list, that is, all the
nodes in the queue. Sqm do to check whether
the queue is empty or not. If you see I have not
written a skillful because of this
violence sorting, I've already checked whether
the queue is full or not. We'll see how objects, so there is no requirement of writing the sum
separate function for it. You'll see what I
have mentioned. It's a simple check,
one condition check. Now, under the private access specifying the class
I had mentioned, this subtype of the node. I've created this node, and then I've simply created
a pointer to this node. So what is this node? First of all, I made a
note since we are using, implementing the queue
using the linked list, we know in case of
the linked list, the nodes are present. And we know in the
notes, first of all, if it's a singly linked list here I'm using
similar linked list, the nodes in widget. First of all, singly
linked, linked list. We are having two parts. One part is having the data, that node and another
part is having link, this link of the next node which is present and therefore. Read the node. I have used destructed
and I've used this data if you edit as representing the
information on the North. So I'm using all the elements. I'm having the detailed data
type and the reason I'm using the another room,
remember is what? It is actually the link, that is the link, as I told you, the second part is a link of the node that is replying
to the next node. The next node. That means that node B, node, that is of the data type
struct node itself, certificates are pointing
to the next node. Therefore, you are
using a pointer. And by I'm using struct node
because the next node is up, note itself so that there
is a reason I have created a pointer on dumbstruck
null pointer to the struct node link. And this is how I'm using this NM creating point does our topic why I'm
using the two pointers, since we know that in
case of the queue, we will be inserting at the end all desert
red and that will be one end and we will be deleting at the end and then
visit plankton. So two pointers are
required because in queue, insertion deletion happens
at defendants as we have seen in case of
stack, it was different. The insertion and deletion, that is push and pop operation was happening in the scene. But in the case of the queue, this insertion and deletion will not happen
at the same Mandy will be happening at different ends and
they produce wine. This required you, if
you use a linked list, then we will be creating in this manner. We have seen there. Now this trial. So that is in such an rebuild. And the legionary will
do adopt that content. Now coming to this, we have seen what all things
are present in this class. Now coming to the main function, I have used this
main function here. So here in this first of all, when you execute your program, the control comes in this main
function and line-by-line, these instructions will be executed initially
so far as to fall. And also one thing that
these functions which are there of this class,
what all functions? You can see all these
functions which are there. That is, you insert
or delete big display q empty always I have
defined outside the class. If you're seeing here I have this is the queue
empty function, then q insert function.
So I did this. The reason I'm using
the class name and the school distribution because I'm defining it
outside the class. So this is how you
should define if you're defining outside the
class, you insert. I'm using in this manner. This is simply its index. If you write the program in
C plus plus language, again, you can see here, this is a
man and how you are using it. So the peak value, so the function name, so before that you are using the class name and
the scope resolution. Again, their display
function again the class name then
scope resolution. Since I have defined
outside Douglass. Now, as I told you, that can break down the CEO
and you execute your program. So the very first line, I'm just displaying the
message, simple message too. In mentioned what,
what is my purpose of my program that
is programmed to implement the queue
using LinkedLists and C plus plus nine, which the food things
which I am using. First of all, you can see
here I'm music and creating. I'm declaring the
variable, option and item. You'll see how, where
I will make use of it. Another thing here you
can see what is this? Another thing, What is this? You can see here
this is a name of the class which we have seen, which I've defined our
showed you that I'm creating the object of this class by
completing the object. Because I will be calling
within functions like to insert q delete big
display of the class, it from outside of the class, that is from the main function. So that is the reason I need to create the object of that class. And then when you can see
the name of the class, the object, I have
created a static object. Networks is static of debt
is by the name q underscore. N LL reports to LinkedList. Q. Underscore LLC. This is a small and
small named shortening. Now you can see here, this is my while-loop. So almost the logic.
You can see here. This is my while-loop,
invite loop. I have written the
switch case and you can see here I'm
using the right one. Disability an infinite new. Inside this while loop, there will be some
condition that will make the control to come outside of this value because you should always
give some condition. And if it's a infinite loop, we should always give
some condition so that it can come outside
of the infinite loop. That your program
should not go like Oh, should not go to
the blocking state. So that is a reason you should. If you write an infinite loop, you should give
some condition that will make your convicted thumb, that will make your control
command inside of this value, that is outside
this infinity loop. Now, if you see here
this insertion. This is just a 2D to mention
the user or that though, if you want to poke on the insertion of
patient entered one, if you want to perform the
deletion operation, enter two. So that is a reason to add
mentioned these four p, four is four displayed,
five is for exit. So all these options I
mentioning to the user, and I'm writing here, then I'm taking this
option in this variable. That is a reason you, now you can see I've made use of it. So that is all the
datatype integer because user can enter 12345. All of these are options. Are
there any of these options using and turn that I will be
collecting in my variable. That is option. So we know that C out. In this way the message
and seniors news to take the input from the
user on the console. Now I have used
which case because there are different cases, that is, the insertion happens, then I will call the insert function if
the nature of evidence Evan Calder deletion function so that board the
switch case I've used. So therefore if user enter one, that is from one to
five, if it enters one, I will display the message as entered element will
be inserted in the QL. Ask user to enter the limits so the data element I can
insert and therefore the CEO to amuse and seen
is to collect them element from the user. So therefore item, what is
this item on the datatype? Item is the datatype
integer you can see here. Therefore, the CNI
views and this item. So I will connect the
input from the user on the console in the
video, that is item. And then I can simply
call the insert function. How I will call the
insert function in C plus plus language, either since I created
already the static object by the static object
dot, you insert, I'll call this
function and I will simply pass this item which users have entered on
the console if you use an enter item is ten in this, in this function
because this function, what is the purpose of
dysfunction to insert whatever user provides the element item. So I have to insert
this item in my queue. This implementation is use a queue implementing the
queue using linked list. So first one, I will be
having my LinkedList. So I've already written here, I have already, this is
my I've already drawn. This is just to just make
you explain an easy manner. So there is these other
nodes in the linked list. You can see this node then this node, this node, this node. Just, in this scenario, we have already
inserted and deleted. And that is a reason practice finding you're responding here. This is optimal
insertion and deletion. I bought this, these, all these nodes present, we will foster hall love, as I told you that
insertion happens at the end and deletion
happens at this front end. Post-op, whenever we are, what logic will be there if
we want to insert any node? In that case will be
inserting at the end. And if you want to delete, any node will be deleting
from the other end. So this other end is this one
that is at the beginning. At the beginning we will be deleting and at the
end we will be, we will be inserting
the elements sources. It will be an easy operation because we are having
here two pointers. Since we know in
case we have seen the simple thing is up
singly linked list. We had the start pointer
pointing at the first node. But here we are
implementing the queue. And we know that insertion
deletion happens at defendants that will
be taken to pointers. So therefore, we don't need we don't need to iterate
from beginning to end. If you want to insert, we will already having a
point that at the end. So directly whenever we
want to insert any node, what will be the condition? And that condition will
be that they're dizzy. If we want to insert the node, possible insertion happens at, note that there is already
pointing to the last node. So if he'd want to
insert any node, first of all, we will
create a memory for that. Since this is using
the linked list, we will put the notes. We will be allocating
the memory using mental or soul function. F4. Effort will never be
needed to insert here, we will be creating, we will be closed off all know, losing a new function in C plus plus b using you in order to create the new node will be
allocating the memory by nu, we will be In the
memory Bonnie mode. And since we already
have a pointer, that is the red pointer
pointing to the last node. We don't need to read from
the beginning to end. We already have 1
that last node. So simply how you
will create a node if you want to insert any element. Since we, Wendy co agreement to perform
in such an operation, the memory should be located. We will use a new allocate
the memory for the new node. And since we already have a
pointer to the last node, in that case, first of all, this are so suppose
we wanted to insert, therefore we will
be first of all allocating the memory from
the new node. So I'll just Draw here to make you
explain in a minute. This is the way I, so if you want to
insert the new node, in that case, what we will do, we will create a node. So this is, I'll
use a new function. I will use a new function that is to allocate them remedy. And I have given the new name, nor name is new node. And this node which I created, I have to enter the input soda, whatever the user
pass the input. Whatever we take the
input from the user, insert the element, that value. We will be simply thinking
we will be filling it in the first part of this node newNode,
that is in the data. And the next part will be done because you'll notice
you'll be creating, leaving need to insert it. And the last, and therefore
the last node we know that link will be the knowledge will not
be pointing to anything. This is a new zone we will
be creating in this manner. And you already have a
pointer to the point them by the name as red pointing
to the last node. So since this is the
new node which we want to insert at the last position. Therefore, now this should be
the last node and we should change the rare in order
to install this new node. So how we will
insert a new node? And the last of this song, after this rare, we have
to insert this new norm. So in that case, what
changes are required? As tough on what we will do, we will be writing
the third rarely. This is a rare where it is
pointing to this last node. So it's linked,
should know it's not, not, not sure, not be knowledge. It is, it should be pointing to this new node because we wanted to insert this new
node at the last board each. And so therefore, what
modification is required? Therefore, we need to simply, right as it will be. It will be in this manner now. So therefore, this red link, we will be writing that
link is equal to pathos, will allocate the memory
for the new node by using a new function you see in
the code how to do that. And then you'll be
writing rarely is equal to this new node
we have created. In this new node we
have filter data of the user to have
entered as an input. To insert this element, it will simply fill this
node with the first part as the database user has entered on the console as the
data to be inserted. And the next, the link
will be this new node. So they were rarely
will be a new node. And now this will be modified. Now this will be that rare
because we know that obesity. Ensure that our red
points to the last node, since we have already inserted this new node by doing
their link is equal to nu naught should be now coming here to point
to the last node. So therefore, what
happens in this case? This is this change that
is now this rare will be, we will be simply rewriting
that is equal to new node. I hope to understand,
understood. You understood how to
insert a new node. First of all, we'll
make allocate new memory for the new node. Then we will be filling
or spark of this new node with the database
user events inserted. The next and the link. But there is a second
part of this node will be because this is the node. So we know that last node
link is always null. And then we have to write that the red which
was there earlier, we will be writing rare
link is equal to new node and then you'll be writing
rate is equal to new node. This is the holiday you
will perform the insertion. So you can see how easy it is. We don't need to enable us from bringing two because
we are already having a pointer that is named as
there will be pointed at, is pointing to the last
node since this is a cube. Now how to perform the
deletion operation? We know that lesion is
performed at the other end. That will be performing the beginning here in
case of a linked list. Therefore, since we already have a pointer to the beginning
or denote by dilemmas front. Therefore, this is also very
easy how we will delete. So we have to delete this node itself where the
front is pointing to. Since we have to
delete this node. That is, in that case what
we are supposed to do. First of all, we
need, in that case, the practice pointing
to this node if this node is
deleted in that Iskra. Therefore this node which is then renewed, need to delete. We already have the pointer and invest plan to the
binding to the first known how to delete so that when we delete this plant, this node will be deleted
and then time should be modified for pointing
to the next node. It will be deleted
neighborhood than the French should be
pointing to this node. Having the data in
this example is 30. And you can see here it
is a link that is link. Already we have this node, so therefore, what is
the pensive ability? How to delete? We have preferred stock
all delete this node. Therefore, after deleting
this node affront to be modified pointing
to the next node. First of all, since we'll be returning the ISI value item, which I just noticed having the data which this
notice having. First we will take
one more point and therefore we will
take one more point. That is struct node pointer. And then we will be simply. So first of all, what
we will be doing, we will be simply using one medieval say item,
the datatype integer. And we will simply
collect the data from this from this node where the plant is
pointing to that paper. Since we wanted to
return that item. And then simply implementing this folding this brand in some, that pointer because I've even one pool the
bleed that point that because it gets stored this
front in some other pointer, we take the backup of that. We can also delete that pointer months that
we modify the front. Because in that case, first of all, we
will collecting, we will be assigning the
front to another lattice, will take on more pointed, that will be pointing to this first node and then we will be incrementing the front by one
position. How to increment? We know it is very easy. Current is equal to friendly. And then this point, since we have already
installed it in another row, pointer, say by under temp, the temp is also
pointing at this node. Then we will be doing
guarantees equal to translate. And then we will be
simply deleting, will call the function delete M, which is pointing
to the first node. And we will be simply making
it and we can guess none. So this is how to perform
the deletion operation. You can see how is the distance. We already have a pointer to the first node that
is by the name frown. You need to simply, first of
all collect the data from this run north to some
variable of the datatype. Indeed, US Census data is
on a datatype integer. And then you have the
store, you have pulled. So take one more point
which will be pointing to this force known so that you can simply then increment the fund to point to the next node so that you
will not lose the reference. Since if you implement
department one position, then you will reduce
the reference. So you have to have you want that reference so that
later you end nodes, you have to delete
the first node. That is, the reason
we'll take one mod m. Then it will be point into
this course notes so that when you increment definitely changed the reference of this current, the current is pointing
to the next node. Then you can delete that
pointer, that is ten. And this is how you will
pop on deletion operation. And how to display all the nodes of this queue that is
in the linked list. Simply, you will be, you will have a pointer
to the front mode, that is by the name node, which is pointing
to the false nodes. So you have to simply take this branch point that
you have to take. Take, take one more point which will be pointing
to this node. So you will by the name temp and you
will be simply iterating. You will be moving to the next
position by using buy it. Since you are having
the link pointer, we will, you'll be
waiting till the end. A new one by one, you
will be displaying, displaying the elements
you need at the last, reach, the last node, that is, node becomes null so that all the
elements will be the space. So all these naughty,
I will be showing the code block ID and we'll
be also executing it. So this is a reason I just go to a new at this example so that it didn't NICU is Zippo. Understand. So now let's move on to the code block ID and
let's see my environment.
5. Queue using Linked Lists Session2Lecture2: Let's move on to the
block ID and let, lets see one by one. So first of all,
this is your advice. So this one is, one
is one such case. We are using this case one
is what? And so things. So you can see here I have asked user to enter the
elements and I've collected in this
video build it or item that is of the
datatype integer. And I've called this by this
static, by this object, I have called this
function Q in sowed, and I pass this item as argument that is already
there, type integer. So what is this queue
insert function? Let's move on to the
definition of this Q1 sort. This is my queue
insert function. Let's move on to the definition on this given sort function. This is my queue insert. And you can see here what
logic I'm doing post-op. All you can see in
case of the insertion, what we are supposed to do. You're supposed to
create a new node. That is a reason
here, the coastline, you can see I've
used a new function. So you can see I've
used new in order to create the new node, New. And then since the
node is older, we have seen in this class it
says, what does this node? This node is of the
struct datatypes. So this node is
having dual members. You can see here.
That is a reason i'm, I'm simply using in
this manner new node. I've created object. So this is a pointer to
the new node and act, I have checked if it is null, I'm simply displaying the
message as space not available. So when this will be null, only when there will be
no space in your memory, then in that case you will be
exerting. This is ducting. So if this is not the condition, this will not be satisfied. That is, if this is successful, then this will not be satisfied. Then your next line will
be executed like this. Then in that case you will
be filling new node data. Whatever you exert pass, whatever user enter the
input, be inserted. Data that I'm collecting in this item that I'm passing as opposed to as a human to
this insert function. So this will be this value which the
user wanted to insert. I will be assigning
it to the new node for spark student node
correspond to the new node. Second part, I'm
writing as null. Why I'm writing is null because that new node which
we are creating, we know that it's
linked, but maybe not because it's the last node. So that's what I'm
doing in this manner. I won't see you understood. Now the logic we have protects. So we have been that
if in this case you can see already that
are already created, if you don't have any
linked list, it is empty. There is no queue is empty. That is, no nodes
will be present. So just consider this. Nice notes are not present. You don't have any note
that for this condition you have to check if your
IQ will be empty. Manual Frank is equal to non-tech means when
no notes are present, then we know that in
that case will be known. Therefore, we have to
check this condition. If a parent is none,
that means you don't have any notes
or queue is empty, that, that is the new node
which you will be inserting. That will be the force
that holds this. We have to modify them. In that case, the node
which you created here that will be pointing
to that new node. Therefore, the new node
which will be there, that will be your, It's done on. This condition
will be satisfied. If your queue is empty, that will trend
is equal to null. New node which you created upon Frank will be also
pointing to that. Therefore this
instruction I have written and else will
not be executed. And then what also you are rare. We will be pointing
to the same new node. Will be pointing to that new
node which you have created. Your queue is empty. In that case, if your
queue is not empty, so this if condition
will not be satisfied. That is, R1 will not be null. That is, in this case, suppose
this all nodes you have already created in your queue. So therefore you can
see in that case, in this case you can see here the notes are
already there. And therefore, you see here that the notes
are already there. Therefore, this else
condition will be satisfied because it
will not be null. We can see your friend is pointing to the
first node is not null because there are some
notes president, queue. And therefore this logic
will be execute the letters, in that case this divine with, I've explained that is the new node which you
have created here. So therefore, what
logic I told you that the rarely will
be called a new node. The new node which
you have created. So that was a red that is pointing to the last
node we have modified. That is the reason you
can see in this manner earlier your red was
pointing to this node. That is a last note. But when you created
a new node and you check that the queue is
not empty, that is rare. Lymph will be called a new norm. This is what I
have written here. And then there will
be also modified, rare will be pointing in
this manner to the new node, that this logic will be there. So I hope you understood the logic for this
insertion function. Let's move on to
another function. So if user enter, then deletion will be performed. Therefore, case two will
be executed. This one. Therefore, by this object I'm calling the delete function. I'm returning some value
from this delete function, which I'm printing here
in the main function. So let's see the definition
of this delete function, what we are doing here. First of all, whenever
we perform delete the, whenever we deleted
delete from dequeue, we have to always check by
any mood is present or not, then only you can perform
the deletion operation. If there is no nodes
present in your queue. If the queue is empty, there
is no question to delete. You don't have to delete
because there are no nodes. So you have to check whether
your queue is empty or not. This is just a check. This is one function
wherein I'm calling is QFD. If the queue is empty,
then it will return one. That means you have to exit. You don't cannot go home. The division operation. What does this QFD function? Let me, I have written
here in this queue empty venue and Q will be empty venue of plant
is equal to null. This condition simply I've
checked and I'm return one. This is simply check
which will return an integer yes or no
that is returned one. That means if this is
empty, then it will return, prove that this
one is not empty, then it will return 0. In ideal condition. It will poke on
deletion on an event that you have some
votes president. When the queue is not empty, then this condition
will not be satisfying. The other things will
be executed simply. I have simply, what I'm doing is how to perform
the addition operation. I've told you first-off
all be 11 more pointer, name this anything you can name that pointer I'm
naming SPN, PTM. And that will be pointing
to this firstNode. Why am I 11 more pointer? Because we know that once
we delete this course note the French should be modified pointing
to the next node. Since I won't, I will increment the front
by one position, I will lose a reference
topic because I want to delete this node after
moving front, it snowed. Therefore, I want the
reference to the first node. That is the reason I'm using, I'm using the one node
pointer that is stamped, which will be pointing to
the personal so that one side increment the
prime by one position, I can delete that tab. There is a reason I
have struct node Tm n by m using this variable item because I want to collect
the data which is present in the post
notes so that I can return from this function. Believe that resin, which
is present in this course, I'm using one, indict them. Now what I'm doing here. So this temp which I have used, whatever plant is that this
pointing to this node. So I want to point to the same node
that I have done. This. Temp is equal to this
assignment is equal to Frank and then stamp data. So since standard
is also pointing to the first node
that holds data will be ten that I'm collecting
in this variability it is. And then I can, I can easily do this operation they're described
is equal to Frank link. I will, since even if I do this, I will increment this
grant will still have a reference because I'm already
collected it in this ten. Then I'm doing them, and then I'm doing the
EMF is equal to null in order to delete
node and then i'm, I'm returning the item.
You can see here. I can underpinning the items. So this is how we are performing
the deletion operation. So let's move on to the next thing that
is peak operation. Now what we are
doing in this piece, whatever the data present in both franc note we will return
the actual first of all, we have to first check whether your queue is empty or not. If queue is empty, then
you cannot perform, you cannot return any value. Therefore you have to give a few end up loop condition
item cannot. Just a second. So therefore increase. In the
case of the peak function, you end up blue conditions. So there is no peak value
before I will exit, the queue is not empty. This addition will
not be satisfied and then I will simply
return from data, which is that then
the next thing about the display user enter for the case four will be executed. So this peak value has simply
been indeed in this case, these end-user enter three, then the peak value
of and turning your gold from this case. And if he was an uncoupled
and display function, that is case four
will be executed on the switch case and
the split function will be called by the subject. In case of the display function, you can see here I posted for alleged check if
the queue is empty, there is no point to display any elements in the
queue is not empty, then I will simply use one more pointer that is
pointing to the parent node. We are doing this assignment. Temp is equal to front, and so there'll be iterating, you'll be moving them
one-by-one and printing it. And even that was
C out and he meant this stem data we
will be printing and you'll be
implementing one-by-one. So we will be doing this till temperatures to null vendor
temperature reached the null, reach the last one. In that case, we will
be simply printing on the data present
in all the nodes. Of the cube. So this is how we perform
the operation for display. And if he was an anchor, and this case phi will be
executed that is exiting. And if you don't end
up from one-to-five, then default that
is invalid option will be displayed
on the console. This is a, this is
the logic about for them implementing the
hue using the linked list. Let's build this program and
let us see the logs below. So if errors are there, you will get in this video. So second, so I'm just
compile this fun. I don't, I didn't go. New arrows are dead, so you are enough
to vote who run your programs are
possible and how to view the loss just will
view and just check on this note so that you can
see the belongs here. Whenever the course you
will get in this block. This is how and
then villain run. When you run your program, you can see here I get this message which I have
displayed in my program, programs implemented queue using linked list in C plus plus. And these are the options which
user have end-user again, and then any of
these operations, if he was I wanted to perform insertion operation user will, I don't want, it will ask me to enter the
element to be inserted. Suppose, entertain. Again, it will ask
whether you want option, the other option you want. So again, I wanted to open
sort. I will insert 20. Again, it allows
Ireland insert diesel. If I wanted to display
all these values are, you can see here 102030, all these elements
are displayed, which I haven't, so did not
I want to perform deletion. I will enter two. Therefore, this ten
will be deleted. Node which was in
certain very false is deleted ready
for so therefore, when I display you calling
you entering four, you can see only 2030 will be it because then
what did you do it again, if I delete simply
and bring to the end, then 20 will be deleted and
then file called Display. You can see this part is if I again delete
actually that is two, then this, you can see the
deleted item is now my niacin. When I simply call
the for display, then in that case
queue is empty, there is nothing to display. So I want this message. This is how you enter three, the peak value will be returned. Now, since your queue is empty, there is no question
of returning. Since bullets again
execute this program. In order to show
you the P inserting n. Again, I will insert, I'll enter to enter row one
and then an island it 20, which item I want to space. If I'll do for you, we'll see 10.128
to call the peak. You can see it written when
he was ten because it will return red doctrine points to
the data of the front node. This is how we have seen all the operations now
for exiting endophytes, you can see the program what exited and then this is also, this is a simpler program. They didn't C Plus
Plus language for implementing the tool
using the linked list. Now, ensure the same programs, same logic will be there for using the C language only
the syntax difference will be there since we
know that is our dividends in C language and C plus
plus in C language, you don't use no class. So there is no
question to create the object of her directly. All the functions you will make Amanullah make us
module functions, separate functions for
insertion deletion. And you will simply called from the main function one by one
you want creating the class. So there is no question of
creating the object offered. Let me, I've already
created a project called C language alpha as simply, This is your main function. When you create a new
project in C language, we know how to play
it on your project. Simply File New and
then he'll project. Just to show you, I'm just
click on Console application, the view port or
new score block, and this is C and C plus plus. So you will enter your
C and you will do next. You write the name
of your project. This is how you
ought to be getting the project for the C language. So this is just to
give you a reference how to create a new
project in C language. Therefore, this is a C program and I've already written
the code for it. So let me just make you
explain one by one. So here you cannot see
any class because it's, This is the C language. That technical rule comes
in this main function. And all the instructions
will be executed. It will be executed line by
line and sequence order. So new at this display,
I'm displaying here. The one display message
will come here. Program to implement
the queue using linked list here just
to display usable, understand what we're
doing and C language. So that's why I have written
in C. Now here again, the variables I have declared
here, option and items. So same logic is damage. I'm explaining U and C plus plus Allison texting while mine, I've used infinite
loop and switch cases, their user wants to
give different options. It will be executed
if user one to exit, user will enter five, so different 12345 in
four different options. The switch case bouquets,
one we're inserting. So if you can see here I'm calling direct the
insert function. Since in C language
we're not creating, we are non-defining class, so there is no question
to create an object. So therefore you're not
creating my object directly. You are calling this
insert function. And the item that user and user having turned to be inserted, you are passing in
this insert function. Therefore, you can
see here I'm using the print f function to
display the message, the scanner function
in order to ask the user to enter the
input on the console. Since in C language
you use scanf in order to ask the user to enter
the input on the console. And this value which users and drink I have collected
in this item media. So in this insert
function will be an drink this in this
insert function. In this insert function
I will be simply passing this item value so that which we want to
insert, an insert function. I'm entering this value which users onto insert
onto the queue. So that's what I'm calling my insert function and I'm
passing this value here. What is the definition
of this insert function? This is the definition here. So the same logic is used as
a syntaxes are different. So here item I have paths and then this insert function
and the same logic. That is, I'm pretty, you can see here I'm essence. This is your C language. Therefore, I'm using
a malloc function in order to allocate the
memory, the new nodes. So you can see this
is a new node, the time creating which I won't use or whatever user enter the input on the console to
be inserted as an element. In this new node, I
will be simply filling the postpartum as
a database user there and don't on the console, then the link will be null because the memory
which I'm allocating, I'm calling from malloc
function in C language. In C plus plus, we have used new, new
function and use new, but in case of the C language, we use them a lot in malloc, the size of the struct node. And then we will be
typecasting to stop node pointer because it
returns, it returns. Here a white point is all
we have to type cast it to the struct node pointer. Then we will be seeing
EMF is equal to null. That means there is no
space and will be exiting. If it returns null, this would be executed if it
does not return null space. And therefore this
if condition will not be satisfied and you will be simply whatever user and career as an input to be inserted, you will be simply
assigning it to the first part of your new
node which you have created, and the second part that
is linked will be null. Now this will be the last
node which is there. So therefore, we will first of all check different, same logic. That is, we will be
checking in vacuous empty, that means the current is null. It will be executed
and the time that is new node which is dead. So new or therefore
we'll check if rank is equal to null
that is vacuous empty, then in that case, the load you have
created brand will be pointing to this else
condition will not be satisfied. Also, the data will be
pointing to that new node. Because when the queue is empty, so when you will be given the parenthesis
equal to null, right? So if this front IS NOT null, in that case, our
queue is not empty. So therefore this condition
will be satisfied. And in that case, the same logic which I have explained
for C plus plus one. So that is, your red
will be X-linked, will be the new,
new, new neutral, your new node we have
named by the name of stem. The full red link
will be equal to. This is not null. In that case, the
queue is not empty, that Buddhist else will be
executed and therefore, the red link will be equal to m and there will be
pointing to that term. So this will be there. And I have given
the name is Stan. The new node which you have inserted rare will be
pointing to that you have to ensure that whenever you insert any element at the last letter L should be pointing
to that new node, because that node will be then asked me and always
ready should be pointing to the last node and we have to ensure all
reads the French should be pointing to the
first known and rail should be pointing
to the last node. So many performing
insertion and deletion, we have to ensure
that are rare in front points to exec
nodes which are there. Now, this is operation and for deletion operation also the
same thing I have done, which I've shown you for
C plus plus to this user. And then this case
two will be executed. We are simply calling a delete function named
simply as delete. In case of C plus plus, you cannot give this
delete function because that witness is your keyboard for
deleting the node. For deleting anything. You use the Delete. Investment in C
language, it's not all. Keep that foot I'm
using by this name. You can even give
quite a good practice. You can give a
different name and C language also that you did not get most out when you write
the C Plus Plus language. Does delete function
will be called here. In this delete function, the same logic which I had
shown you for C plus plus one. So first of all, you
have to check whether queue is empty. In
the queue is empty. You cannot delete. That won't be an inode present
that can be deleted. This will be executed if Q
is empty and you will exit. But if the queue is not empty, that means some
nodes are present. In that case, what you
are doing supposed to do. First of all, you
are supposed to take one pointer temp and that point, that attempt is equal to from wherever the
front is pointing, temp is also pointing
to the strength node. And you also taking one medium entitled the data that
you're collecting from the stem that is from this horse nor you are collecting in this
medium will item. So that later you can
return this item. Now you are in, you can do this operation that is no
problem if you increment by one position because
already you have taken the reference in one
variable that is there. Then you, and then
you can click that. And that is, and then
you can let them know and Indians and you
can return the item. This is how you perform
the deletion operation. Now the next the next
in which comes here is the peak values of peak
value will be the value which is returned from
Doctrine friend pointer. So that when the
peak fossil fuel, you'll check if the
queue is empty, you cannot perform the peak. If the queue is not empty, this if condition will
not be satisfied and therefore you are
returning pointer data. The next thing is that about
if you enter display few, enter in your row
here for photos. Switch case is for display. What the logic you have written, the same logic which I've
shown in C plus plus also. That is, you have to
check, first of all, before the spring
we are protected if the queue is empty or not, because if Q is
empty, you cannot walk on display operation. There won't be any notes
which you can display. That way, queue is empty, then you have to exit. If the queue is not empty, then it will not be satisfied. And therefore one-by-one and other instructions
when we executed. So therefore to display, you are taking on more pointer
pointing to the front. Therefore, these two lines
I'll go instructions I use. You are checking till
you reach the end. That is time normally when
I'm on my mind displaying the value by calling
print f function, you are using a format specifier percent d because
you are printing them data that is on the datatype integer
and the stamp be done. And you're incrementing
one by one. So this is how you use the display function and this index differences
on either. Now, for exiting if he was in and then k is five will be executed and you will be
exiting by calling exhibit one. And if it was or don't
enter from one to five, none of these values
using them default, this printer, it will be giving the message, messages
invalid option. This is how the complete
program is there. So don't worry, I
have shared on the C plus plus and C program you, so you can simply copy paste the whole program
and your program. And you can simply are copy-paste this program
in your code block, new project for C
plus plus and policy. And you can execute it. So you can refer
the code itself. How to build same build, compile the current file. It will give me the big loss you can see are no arrows are there. So we can proceed running the phone by fault and
bring well-done drawn. By entering the build Enron rope will get this message
programmed to implement. You're using linked
list and see if I enter one fall on social economic
element to be inserted. If i, and third row 17, again option again, I want
to insert again Nine, 45. Again, I wanted to
say island TO one. And then I will enter
50 next time if I want to display ALU for so
174551 to delete enter, you can see here 17
will be deleted. So this was inserted very
false, it will be deleted. So this is how we are. We have maintained
that q then if you won't gain on to the ADP
folder to, it will delete 45. So it is really a
thing in sequence at peak older display,
we will get only 50. If we will call up
being the district, return different
values written 50. Again, I'll perform
delete operation again. 50s repeat again. Split since there are no nodes
present in your keywords. So it will give me the message. You end up loop condition. If you under pro condition
item cannot really suggest I can modify
this message since I, I'm displaying you
underflow conditions, so there is nothing to display. So we can modify this
message from the console. So therefore, if you see here the peak value of the
feet function which is there, you can simply messy display
function we have weekend modifying your idea if it was empty. And so nothing to be displayed. You can give this message here. Whenever you are calling
display function and your queue is empty. So this message will be printed, queue is empty and so
nothing to redisplay. This is how we have full foam, different, different
operations, so it just exits. Now I'm done this
complete session, but in actual knew the program written in C
plus plus language for implementing the cube using the linked list as well
as we have executed it, as well as we have written. We have seen the program in C language for implementing
queuing using linked list, and we have executed it
in the code block ID. So I made these programs
in redundancy Plus Plus language and see
for implementing queue using linked
list access to you, you can simply report it. You can simply copy paste
the same program in your different
different projects was he language and C plus plus. You can execute it. Let's meet in the
next session for now. Thank you. I'm fine. Thanks.
Are not prints. Bye.
6. Queue using Circular Linked Lists Session3Lecture1: Hi, welcome to the new session of writing the program
and executing for implementing the queue using
a circular linked list can see language as well
as C plus plus languages. So here we will be doing the practical session
will be creating new project per board C language and C plus plus language
in the code block. So as I told you, scored block
ID, this freely available. You can easily download
and install it. You can see how to do install it by simply Googling the steps. It's very easy to install and you can just start the
practical session with me and have the hands-on
of this data structure. In this data
structure that is Q. Now, just quickly
revising what does this Q and what is this
circular linked list? This skew that structure. Insertion and deletion
happens at different ends. Here it follows people that is supposed to be forced
out. What does it mean? It means that animate
which isn't inserted, boys will be deleted. Posts the element which is inserted last will
be deleted last. Here the insertion happens at the end of the list in case of the queue and
deletion happens at the beginning of the list. Now since we will
be implementing the skew using the
circular linked list, what does this
circular linked list? The circular linked list
is a linked list in which the last node will be
pointing to the first node. You compare the linked list with the circular linked list. So in case of the linked list, if you see that the last
node link will be null. But in case of the
circular linked list, the last node link
will not be null. It will be pointing to
the first node so that then you want to add
the last node you can simply reach
to the post notes, since you have the link
on that last node will be the first node for what will be the difference in the program in this circular linked list, when you implement
that you're using the circular linked list, the difference will
be that you don't require and more pointer that is front as we have seen in case inhuman did the queue
using linked list, we required two pointers, the red pointer and pointer
because we don't have, because we didn't have the
reference to the first node. Since in case of
circular linked list, we have the reference
to the clause node. By this last node itself, we know the last node link
is equal to personal. You had already having the
reference to the personal by this last node itself in case of the circular
linked list. So here you required on the
one pointer and that is the point that will be
pointing to the last node. You don't require
the front pointer in case of the
circular linked list, but in case of the in an
earlier session may be implemented queue
using linked list we have seen with
quiet to Brian, Brian pointed and red
pointer because we, in case of that linked list, the last node link wasn't there. That is, leaves him, he
didn't have any source to reach to the first
known by this last node. So that is the reason we
require two pointers. Franklin, point
that a linked list. But in case of this,
in this garden session that you'll be using a circular
linked list, had a VR. In circular linked
list, the behavior is lost nor will be pointing
to the first node. And therefore, you
require only one pointer. That is a rare pointer, and therefore interlinked,
we will simply get the host. So that is the reason we require only 1, that it is red point. You will see this, all these things in our program itself, how we will be proceeding up for insertion and deletion
and other operations. But implementing the queue
using circular linked list. Just quickly. Moving to the project that
is called block idea, which I have created
the code block ID. Now. I haven't opened
the whole block. I leave it in. I've already created
a new project for C plus plus language. Then after execution
of this program, then we will also see the
program policy language. Now, impasto fall. You see here how to
create a new project. Just quickly
mentioning it by mu. Click on Project, then click
on Console Application. Just click on Next here
you will be having whether you have to write the
program in C or C plus plus. You had this project
is what C Plus Plus click on Next and give them meaningful short name so
that you can understand what is the purpose of your
program and then click Next. So this is how you can
create a new project. Or just moving through
this chord which is written in the C Plus
Plus language for implementing queue using
circular linked list. First of all, you
have to mention this header file, iostream, you notice is
useful input output when we call functions for that, that is cout and cin, then this namespace,
std, this class. For this class, if you see here, you can give the
name of the class. So I have given here,
this is my name of the class that is given
Linked List underscore IM VL. Now in this class I
have mentioned I have, I'm having public access
specifier as well as I'm having the access specifier here. What I have done in this public specified in the
constructor as public, I have made the
destructor as public. If you see here this
function that is q insert and delete 50k
display enqueue empty. So these functions I
have made as public. And what is the skew
insert will be doing. It will be inserting the element
in the queue Q deletion. We'll be deleting the element
in the cubic will return the value of the interview and display will display all
the elements into q, then q empty to check whether
your queue is empty or not. These functions are public and what is private flight
rate is your I have created since we will be doing using the
circular linked list. So what I'm doing, I'm creating a struct node here in this manner because this is
our circular linked list. So each, each, we refer the circular linked
list in which there will be the nodes
present in each note, there will be the
dark present in it, and that will be up. There will be the
data present in it, and that will be the link which will be pointing
to the next node. So therefore, since the link, therefore the
datatype will be on the struct node point
that because it is pointing to the next node
and that node is on, new node itself is
struck know debtors. And so therefore, you can see here this is the it is
having two members. That is one, that is
the first part of the notice data and the
second part of the notice, the pointer to the next node. And therefore we are
having the data type of the link as struct node star. And then this, what I have
done here in the next slide. I needed the point,
don't want anyone coming into that red point though. This is pointing to the node. So this will be pointing to the last node in the
circular linked list. As I've mentioned, you'll be
doing require two pointers. That is Frank pointed and
then pointer reason, um, that this red pointer link in case of the
circular linked list, will be, will be the first node. Therefore, we don't require the front point and
you will already get a reference
to the first node by this red pointer itself. In case of the
circular linked list, this is a diagram
just drew make you explain what is a
circular linked list. This is a diagram of this stuff. This is different example in
which the nodes are created. You can see here how this circular linked
list loop looks like. You can see here this
is the first node, second node coordinate
forth known. This rare, which is
pointing to the last node. So this is the last node.
Let's stop the nodes. And you can see here, this is a rare and cluster for this, I have modified this. It was, it calls. So this is your
circular linked list. This is just an
example to show you how the circular linked
list looks like. So it is a list of
nodes. You can see here. This is a red node which is
pointing to the last node. This node, if you see the link is 100, what
does this a 100? It is the address
of the first node. You can see this force notice
having the addresses 100. So therefore the link of
this rare will be a 100. That means that node link is equal to the first node by node, if you have a pointer
to the rare alone, then you can directly
to the US non-health by simply it's linked as a double course notes so you don't need require two pointers. So I hope you understood, so you can see how it
is, how it looks like. It is circular, therefore, the reason it is called as
a circular linked list. So here we are using a
single circular linked list. So just moving onto
them, broken down again. Now, I have seen more. The class looks like what, what is the definition
of the class now, all these functions
which are dead, I have defined
outside the class. You can see here, that
is the reason I'm mentioning the name of the class like this and that
scope resolution, since it is defined outside
the class data skew empty, then the queue insert. All. You can see. I mentioned an e-mail, the
classical resolution. Then this q delete again, Amit mentioned the name of the class and scope
resolution for all the functions I have
defined outside the class. Therefore, we have
to give the name of the class and scope resolution. Now just going to the main function because
when we execute the program, the control comes who don't
mean function, all the lines. All the instructions will be executed in the sequence
manner line-by-line. So first of all, this is
just a display message that is cout program to implement the dual using
the circular linked is here. This regardless form
this display message. Do I understand what
is, what we are doing? What is the purpose of a program to implement unions
in circular linked list. Then I have declared
these variables. You can see option and item. Then, since this is a C Plus
Plus language I have added, I need to exist
different functions from the main function
from outside the class, where I need to
create the object on the glass for so that I can use the member functions on debt glass from
outside of the class. So therefore this name of the class Linked List
underscore I MPL and the previous tactic object by the name as you
underscored alleles. So now you can see here, I'm using this by loop. So till now we have seen
the program in which I have seen minute or implementing the Cuvier
using the while loop. Because we know there
are different options with user onto and for home, like insertion, deletion,
display and exit. So that isn't, isn't merely
using the while loop. This loop will be running infinitely and you
don't want to exit. We have given the provision to exit from this infinite
loop by giving this option that is
exit that doesn't even need will avoid bringing the program to go
to dinner tonight. If users don't
want to give these options use against and P exit. We have written, we have
implemented how to exhibit also. So we are in this
vitamin and we are using the switch case since there
are different options and we have to implement for different operations that we'll be using switch case if the user enter a
month and the switch, then displacement will be executed in which it
will be inserted. So we have provided what
all options user can provide 1 and social tool for deletions if he
was entered three, then there will
be picked for for displaying Piper exit
so you can enter any of these numbers and that
number's we are accepting in this option and then
using the switch option. But depending upon the numbers
which user has entered, the skills will be executed. Case one, if I wanted to
insert, user will enter. One Is one will be executed and these instructions can be executed if he was an intent to, that means you don't
want to delete elements in this manner. So I have called the
delete function. So how, how I'm calling in this, since we have created a
static object of the class. So by this static
object dot the name of the function and I'm
calling I think item. So if you don't want to insert
any element, user will. First of all, we
are asking user to enter the element
to be inserted. So user will enter any element. Here we are. We have taken this item of the data type. You can see here. Option and item is
on datatype integer. User will enter integer
value and that we will be as an argument
to this function, that is q insert by the static object we are
calling this function and we're passing this item which users and third to be inserted. Now, what is the
definition on this insert? Let us go to the definition. So foster hall. In case of the definition,
you can see here, you insert the
element with user him and we have passed as an
argument to this function. Therefore this item
we will insert. Now how to insert in case of
the circular linked list. First of all, we know
that the insertion happens at the end of the list. In case of the
queue and deletion, we will be in shutting to do at the beginning
of the list, right? And here we are having
only one pointer that is pointing
to the last node. So we need to do the insertion. So first of all, inserting, let us, let us move to
the diagram itself. So he applies to Hollywood. He had to insert one node. This is how we will be inserting
a new node of that is, insertion we have is done
at the end on the list. And therefore, you know
that we are having a point, that point to the
last node here. Now, this is a new node. First of all, we will create
the memory, will allocate. The memory for this new node, will be known how to allocate
the memory and even use, we can use, we can use mu, we will call new, we will use a new
and we will create, will allocate the memory
for the new node, the item, the element, the value of user haven't done that to be
inserted that value, we will be simply filling this first part of this
new node and add value. What will be the second
part that we will see? How to insert this complete this node at the end of this
circular linked list. So far stop on, let me know. Circulant increases whereas
pointing to the first node. Therefore, the rarely
will be the first node. Therefore the new node
which we will be creating, since we'll make that
known as last node. So therefore, this should also
behave in the same manner. That is, it should be, that should make
Melanie to point to the node how to get the
firstNode reference. Bye excel, because we know that rarely is equal to four snowed. Therefore, we can
simply simply write that the new node will be
equal to the node link. Therefore, whatever
the link will be there of coping with the link of node. I hope so You Watson's
view will make this new node as a last node. So therefore, this last node. What is the behavior
of circular linked list which should be
pointing to the first node. So how do you get the
reference of the first node? We already have a red point to the last node and its
link is false node. So we'll simply copy
the link of the red to the link of them. New node. Then we get the new node
link as the first node. Now, after this red node, since this new node
in Mecca, last node, therefore, that after
this red link should be, should be equal to the new node. Because the link of what will
be the link of the node, it should be, it should
not be there or it's not. It will be the new
node because we are inserting this new node
at the end of the list. So after this read,
this new node comes, and then after this new node, the link will be a link on
new node will be a personal. Therefore, we will write it. What we will be, right? Node link is equal to new node. This is how will we will get the red node link equal to new node and how we will
get the new normal. Yeah, I've seen first of
all, the red node link. Link will copy to
the new node link, and then the link will be
equillibrium new node. Then. Then this new
node will be done. Will be writing as we
will simply then, right, as that is equal to new node, we'll write that condition. So there'll different variable appear different conditions. So if U is empty, do is emptied. Here you can see there are
notes present in your queue, but there are no nodes present. Your queue is empty.
In that case, what you are supposed
to do in that case, since there is no node
and we know the I implemented using
circular linked list. So first of all, we'll allocate the memory for the new node. We will, we will the first part of that new node by the
value which user entered, then that new node
link will be simply, again, will be the
new node itself. If it is the empty queue. In empty queue there is no
node presence, only one node, whatever you will create new, allocate the memory
spot of that new node. Second part, that is the link of that new
node will be the same for that new node itself because we don't
have any other nodes. So that is a reason
we will neglect that there are
indifferent condition. This condition which
I told you now, whilst there are some nodes
present in your queue, but if there are
no nodes present, your queue is empty, so you
have to do in that manner. So this is how you have to
do the insertion operation. So let's move on to the
logic to the insertion. Now dipole, you can see here
we're at what we're doing. We're allocating the
memory on this node. This node, this node we have
seen in our class itself, we have made it as private. It says struck noted cell. And we are having two parts. First part as data, second part as a board in case of the
insertion operation, if you'll see I'm
creating a new object, I'm calling the new, and i'm, I'm calling the new empty node, that is by the name noon
mode in this manual. So I'll use nuisance. It's a C Plus Plus language and I'm checking if it is null, then this new node is not as common sense null whenever there is no space in the memory. Therefore, this message will be displayed in this
site in this manner. Then if it is not null, well, then well and good. That is, then you can simply proceed with your
father row operations. That is, memory is allocated. Therefore, you will
fill your course part, that is data will be
the item values are I have entered some value
use which you have pauses and argument in this
function that you will, that first part of this
new node will be that item and what will be
the last part here? Therefore, you can see here the new node postpartum
will be that item that is n. We will see how to get
the link of the new node. So as I told you, there will be different,
different conditions. So if your queue is empty, so SQL empty to check whether your queue is empty when
the cube will be empty. Here I've written the
definition hot the same. So here this function definition is van, you already smell. So since you are having only 1, that is a red pointer, you
don't have a parent pointer. Therefore, if this red is null, that means you want
to queue is empty. So again, you have to
check this condition to ensure that the queue
is empty or not null, that music queue is empty. So in that case, you can proceed like how since
there is no nodes in your, in your queue, therefore simply the node which you have
created in this manner. That, that will be
simply your red node. So there will be that new node. And since you don't have
any notes in your queue, and therefore the new node which you have
created that will be your red node and that
new load that you, That is, that is there. Its link will be
equal to the red. I hope you understood
this thing which is bed that it will be only
sensor queue is empty, we will create a new node, so that will be one node and that link will be done
even though the cell, you can simply write like
this, you can answer right? Instead of new node link, you can write a red link
equal to same thing. Investigate means that
the new node which you have created volume
and notice you have created it's linked will be the same new
node itself because there is no other
nodes so that you can simply link to that node. I hope you understood
what I mean here. This is the thing which
comes into picture. Now, this queue is not empty. In that case, the thing
which I mentioned, you'll allocate the
memory for the new node. And then how do we get
the link of the new node? Since we noticed that new node
will become the last node. And therefore the
last node links should be the post
notes or how we get the reference to the first
node by this pointer itself. So there isn't a
pointer link we know is equal to personal data
copy to the new node link. That is a reason you can
see here they're linked. We add coping to
this new node link. And that link will be
called the new node. That is rarely will
be equal to new node. And then since new
norm will become the rare no definitely
instruction is equal to new node. This is the complete it and sorting the
elements in the queue. The different conditions. That is, if your queue is empty, audit when the
queue is not empty, then we'll have to
perform the operation. Now just going to the
main function wherein we will see for deletion operation.
7. Queue using Circular LinkedLists Session3Lecture2: In combination, if they
use an entertainer, then case two will be executed. And then we're calling
the delete function. In Delete, it will return item. And we'll print in the
main function itself. What is the definition
of this cube in it? Let me go to the definition
of the skew DD acuity lead. First of all, let me move to this diagram of
the circular queue using the circular linked list. First of all, we
note that deletion always should happen at
the beginning of it. Since we don't have a V, that is another
point that S prime, which is pointing
to the first node. No problem. In
circular linked list, the last node that is a red
link will be the host node. So by that red link, you will get the false node. And then you can perform the
operation on deletion as noted cell that is
at the beginning of denoted cell, that board. What you will do here, if you post up on UBI, check for different
different conditions. If Q is empty, there is no point of bleeding. So you have to check
this condition. If the queue is empty, then that means you cannot delete because
there are no items, but isn't this condition you
have **** deck and other, and teaching is that if you are having only one node present, so here you are having
multiple nodes. Don't consider this example. Just consider if you are
having only one node, which is having the value
as ten images in which you're having this man,
that is this node. Suppose you are having this complete node that is
on the OneNote present. And this is your,
this I have added. Now just to show that if this is your circular linked
list, this is your Q. We are having only one unknown. You can see the
element and we know that the link dispose
of this new node. It will be simply
since the one node, it will be simply
pointing to itself. Therefore, you can
see here this node is having the address is
present at the moment, is present at this node is
President memory location 100. And record the link will
be this node cell level. You are having a 100 itself. So this is how it looks like. In this case, if you have to
believe this node itself, what modification you have to. First of all, since we have to return the item
from this Norwich, we believe that will
be built first of all, create point that
itself because we have fossil fuel to return
this value and we have to also free the memory which
is taken by this node. So there's a reason rebuild
simply check first of all, this condition if that
link is equal equivalent. So this is the Internet
which is present. This is your red pointer. That is, if you see here this, let me give the name. This is your red,
which is there. So here this node
is named as rare if it is having the value a 100, if it is equal to, if it is equal to read, that is, that is
what a 100 itself. You can understand this
condition in that case, you are having only one unknown. In that case, the chain
decided that first of all, you weren't taking
a more pointer. Struck note. In this manner. You're getting one more
pointer temp and you are assigning the red M for them. And red is point, damp is also pointing to that. It says to this node, you are collecting the data from this node to some media items. So you are declaring this
item off the datatype in detail during the claim this item two of the
datatype integer. Because you have to
return this item. And then after you
got this item, then you are suppose to at
our deallocate the memory. This is occupied by this mood that what you
are doing three of em, and you do feel that this stamp is also
pointing to this node. Red is also pointing
to this node. You have the allocated the
memory by doing three of them. And you have to ensure
that you are rare. And ten, which is pointing
to this node also, you have to answer
initialize a bit. This is a good practice. Always remember if you have any pointers pointing
to that node, if you have yellow
kingdom remedy, you have to do and chart
initializing as this is this, you have to always make sure
this is the logic for that. And if you are not
having OneNote, if you are having multiple
nodes that is in this manner, this is your succulent English, not in this condition. That is, in this condition. The logic which I told you now, I'll do now this fellow
here you are having. I didn't know what's
present in your Q. So, in that case, what you
are supposed to do here. In this case, first of all, we have to delete this node
that is disposed node. So we had already, we are having that head pointer pointing
to the last node. Do delete to the first node. First of all, we will
read through this course knowing how to reach
to the first node by simply rare node link we will copy to someone
more pointer node. We will link is
equal to first node, so therefore we will create
one pointer and this red, we will copy that link to that pointer so that we will get the first
node in this manner. You can see here
the stamp we have already declared it
here in this manner. Ignore the red
link is wonderful. It's node, so therefore
you copy to the m. Therefore we got
ten pairs of Osmo. Do you want to delete
that node cells and deletion happens at
the beginning of the list. The first node that is stem. And now first of all,
we'll collect the data, report the collected
data to this item, items on the datatype in
detail you have seen. Then after collecting
the item from there, then what we will do, we will delete this node. What changes can happen
if we delete this node? In that case, this node
will be the first node. So this red links should
point to this first node. We should also maintain that. When we delete that, how would you modify it? If you delete this node, then rarely will be not this
node since it got deleted, it will be this node
so that both rebuild simply write that readily
will be equal to, we know this is the temp, so it will be equal to
temp link because this, after deleting this node, this will be the first mode. So how will get the reference to this node simply be known, DR. having ten that is pointing, there is a force note that
this pointing to this node. So this node, that board, what we will do, we will write re-link is equal to template. In this manner, you can see
lending is equal to ten. So that will be gone.
Rare pointing to this. And then in that indent later then we can simply
three, not two. Then we can easily
allocate the memory, will look the M, this VLDL are getting the memory which is
occupied by the stem. And then we add temp is equal to null after LOD allocating
the memory will write M physical and we'll
return the item from this, which we have view
collected in this video. But this is how we perform
the deletion operation. I hope you understood
this logic. Now again, moving to the
main function and seeing for different things like if
you use it enter three. That is three option, that is this one. Bookcase suit in case, case three will be executed and we will call a peak punted to simply return
the front value. So what is the definition of this peak value is aggregation
Hill are defined here. So first of all, we have to check if the
queue is empty. We cannot. There is no peak value because
the peak value returns a friend that is the beginning
of d value of the node. Therefore, the QM
TV, no checking. So it gives us MDB
cannot return anything. The queue is not empty, then what we will be returning? This is a thing we
will be returning. The queue is not empty and
that is the peak value. It will simply
return this thing. What I'm doing exactly, since I'm having only one
pointer that is red pointer. Now, first of all, the peak it returns the
value of the first node. And we are having the pointer to pointer as a red node
pointing to the last. So how to get the value
of the first known? We know that red node link
is equal to false nodes so that link data in the octopus, No, that is a reason. Week from the red
we can reach to the first node since
we know that link is equal to false node and its data will be
equal to that value, will return has a peak value. So therefore, you can see here, since it will give the first
node and it's deep enough, you will be simply
returning that will give you the value
of the force notes. So this is how we
have to poke on the peak operations
so you can see how things changes whenever you are implementing
using the linked list, when you are implementing
using the saccule and English, you should know what
is linked list, what a circular linked list. And we know the concept
of the queue insertion happens at the meaning of insertion happens
the end of the list. And bleaching happens at
the beginning of the list. And we have to check for
different conditions like U is empty or not,
all these things. Now if the user
wanted to display all the elements of the
queue user when it's empty. And the Ford case Ford
will be executed. What is their definition
of this display function? You can see in case
of the display, we are checking if there is
no elements present in EOQ, there's no point to display. Even check if queue is empty. In that case, simply, you will simply exit because there are no
elements in your Q. If Q is not empty, in that case, what you will do, first of all, the thing. That since we have to
display all the elements in sequence order this from the
post node to the last node. So what I have done here, I have taken one
pointer that is stamp. You can see here in this manner
struct node pointer ten. Since B one will start displaying elements
from beginning of the note, so readily will give
me the host node. So that would force
I will display the value of the first node. That will give me the force. Note that this M here, I'm using a do-while
into what I'm doing. In this first time. They are not checking
any condition. Simply it will display me
that Md dot m data is what? Since temp is equal to red link, that link is posted notes. So therefore we will get
this ten by this CL. And then what we
are doing in VR, incrementing the
M51 for division. So now point here. Then we add after doing this, then we are checking
this condition. This condition is
satisfied then only this. What does it mean here? That we will do this? Again, this will be executed actually underneath
or this condition. If the temp is not
equal to red link, then only this
again this book and do the instructions within
there will be executed. You will keep on doing
this instructions on me. If this condition is satisfied, if this condition
is not satisfied, then you will not execute
this instruction. This is your BYU. Now, what is this condition? We have displayed the
value of the first node. Now we will display one by one. We would move to the
next node and we display each of the nodes. Since we have, we have display
initially the first node, there'll be displayed
the last node value. First of all, what
is this last node? That is a reason I have given this condition that n should
not be equal to red link. So what is a red link? Actually, this is your read, its link is equal to false node. So you have to check that till you don't reach to this node. It said you have to keep on displaying because you
started from forests when you didn't start from
the last node because the order of displaying
Weibull or the student display from false node to the
end on the node to the last node that will be
started from the poets node. And you have to keep on display
the values of each node. Then you will reach
to this node instead. In reach to this node, manual traverse all
the nodes one time. That is a reason
what will be the rarely it is a postsynaptic
cell debris or protect this condition you
don't reach in this stem to 1. First you have displayed initially in this
vendor was executed the standard what displayed
then for this while this condition is still not satisfied because
temp is pointing. Because temp is pointing here, you have displayed this value, not empty is pointing, is not equipped with
the post notes, so they will display
this value again. You will reach to this
node temp is not equal to the post-meal display
the value of this node. Then again, you reach to this node temp is not
equal to the force normal. Display this value again, you will indeed each year now the temp is equal
to the force node, so then you will come
out of this execution. You will not display this. And finally, you will get
all the notes printed one time from beginning
to the end of the list. So this is how you have
to do the display. So I hope you understood the logic we are doing
now is simply executing. How to execute. First of all, you need to check. You need to compile your code. You can see here this
is a blog how you got mu and I've checked on the
loss, this is a video. Now how to run, build and
simply build and run. If you build and run, you
can see I have simply written this message
programmed to implement the queue using circular
linked list in C plus plus. If I want to perform
insertion, I will enter one. Enter the element to be
inserted, supposed to enter. Again, I will enter one again. I wanted to insert
that reason and therefore enter the
element in the queue. If I insert as 30, again, I want to insert if
I enter the element as 0. Now if I include a splay added
display by entering for, therefore you can see it is
displaying in the sequence or the 203020300 API wanted
to delete, I will fall. And third to that where you can see two is
deleted that to 20 or you can see 20s deleted when he wasn't
sorted post and delete it. Forced not again, I wanted
to perform deletion again. You can see thirties deleted
again, I want to delete. Then if I wanted to display, you can see on the element is 0, only one element is that
it is displaying at. So if I wanted to both
on peak operation, It shouldn't have
done on these EDL. So you can see the
peak value is 0. So this is how we have
seen different operations of now if I wanted to
exit eval end of pipe. So we have seen all the things. The chart options which
are provided to the user. This is how we have seen
the program in the C Plus Plus language for implementing the queue using
circular linked list. Now the same board, same logic is used if you
write the same program in C language only this
index differences there. Now I've been just
opened a new project. At the project, this is the
other project for main.cc. You can see here, this is the project which I
created for C language. You can create a new project that's shown you how to create. Click on File and then New. Then simply dismantle project and console application
and just click on Next. This time you will
click on C and then click on Next and you will give the name
of the project, meaningful name, short
name, and then next. So this is how you
can create a project. I have already created a project or policy language
that this may not see I've created and I've
written these logic quadrant. Let's see the other differences. Since this is not a C
Plus Plus language, you won't have
class present year, so there is no question
of creating an object. You can directly create your modular function
here outside. In this manner, you can simply call this function from
your main function, so this amine global. So you can see here
these header files have included and this
node which is there, I have created global. This is struct node since we
are using circular linked list in which node has
the postpartum as data. Second, notice that
pointed to the next node that would dissolve datatype is struck node
pointers. Same logic. Again, you are having only 1
though to this struct node. That it says a rare since it's, we're implementing queue and
using circular linked list. So you have only red point
that we don't require Frank pointer because we are
pointer link is equal to, we know we can get
the first node. So that will be don't require a different pointer
pointing to the first node. By this pointer only we can do the jobs of
insertion and deletion. We have seen that book you insert deletion same
or things are there. So this from this main
function when you execute your program control comes
in its main function. Nine by nine instructions
get executed. You can see here I'm calling the print f function and CB call the print f to
display the message on the console and
scan f to give, take an input from the user on defense zone in
case of C language. So here this is simply the
display message which will be coming in your row, unsorted. What you'd be doing
program to implement you using circular and
English and C language. Now here you can see here
we are declaring variables. Same logic again, we are using infinite loop while one we
again with different options, use again into any
of these options. So you can see syntax differences
that I'm calling print f function to display them as scan app to accept
the input from user. I'm using entered one case
one will be executed. That means you have to insert
any limit in the queue, will ask the user to
enter them in the queue. So we'll collect in this item and we will
call this inserts. You can see how I'm calling. You insert directly. I'm calling the
queue insert since itself C language directly, I can call the function
in this manner. I'm passing this argument. Now the definition is
same if you see here, logic is seen in Q1 sentence, it says C language
and not use new. I'm using my lot. First of all doing sort. We use a malloc in C language. We allocate the memory
and this manner we bypass struck
mode point though, this is how we check the same logic we are
taking EBIT is null. That means the space
not available. Again, these things
we are doing here, you can see here
what we are doing. We are whatever I didn't, he was having good,
I have simply, I'm filling it in this course
part of this new node, the same thing, then
I'm checking if the queue is an
EM on doing sort. I have shown you the
logic that is no, not present and you wanted to insert a new node that
will be only one node. To handle getting them memory. There is no node,
an entity and you wanted to insert
that new node so that new node will be
the first node, right? And since it's a
circular linked list, that new node link will be done. So this is what you have to do. When queue is empty,
the queue is not empty. There's some nodes present. Then we have seen how to insert. We will simply, since we
will do in social and the last and last
position of the list. So that would be have
seen how to insert. The new will allocate a new
node memory for new node. And then that new node, which is that how to
get the link up it. By this fairly readily, we will simply assign the new node link and then rarely will be
equal to the new node. And then we have seen this
illogic code to insert. Now this is the
operation of insertion. If he was at a different option like user enter, like this, if he was hit Enter, then this case two will be
executed via calling the function and return an item. What is the
definition of belief? Same logic. Is there just directly, you're
following the queue delay. Here. Again, I'm checking
the queue is empty, there is no question to delete. There are no nodes present. If you had to having on the
bottom node that you want to delete in that how protect if you are
having only one node, this is the condition that is epidemic is equal to itself. That means there is
only one node present. Then this is the thing
you are forced upon. You are taking one
temp pointer, you are. In the US and assigning rare to the stems are pointing
to the same node itself. You are collecting the
data from data to items, items of the datatype
and Vigil, same logic. And then after you
selected this item, now one node which
is only present you under the thing that's of the M and you have to do this. This is the logic for that. If there is no one node that
are marketed knows Dan, this logic which you
have post-op one, since we do the deletion, the beginning of the list, therefore, we know that link
is equal to that force moon. So that would readily we are
collecting in this endpoint. Therefore it's not
then we're collecting the data of the
stamp to this item. Then since we manually
delete the first node, the next node will be
the first node itself. So therefore the red links
should point to that node. This thing we are doing, that is this stamp link which will point
without employing, because when we delete them, the next node will be
the cost no decode. And then link will
point to this new post. And then after doing that, we can simply be the first node and then,
and physical to not. And then finally we
can return items. So this is how we have to
perform this operation. Now the next thing
is that again, the user and Guthrie
Ksp will be executed. They're calling the function. What is the definition
of the function here? Again, since we
are having only 1, that is red pointer. So this plus we'll check
if the queue is empty, there is no point of returning any value because
no node is dead. If Q is not empty, then you will do in this manner. That means how to, the peak will return
the value of the first known how to get the
value of the first node. We know that the post notice
what the red link is. The known rarely will be giving you the first known and its
data will give you detail. This is how we'll return. Now, again, reaching to the, again linked to the
main function for different operations
like display. Now what does display function? We'll display function
here is first of all, you can see here this
same logic which I have shown you for
C plus plus also, first of all, you are treating their temp and you are checking. Queue is empty. There is no question to
display any notes in your row. Because the queue is empty. If the queue is not empty, in that case, what you
will do first of all, you have to display from, from beginning of the last
position of the cube. You will collect this link and
this stem and used simply, you are using a do-while. Same thing which I've done in C plus plus also logic is same. We are just splitting
this first node value and then we are pointing
to the next node. And we'll check this condition. Didn't it doesn't
reach to the Postman. You won't do display on
my mind all the elements. You, this is how we
have seen how to do. Now. We are done with complete check for
Q will same logic, that is how queue is empty, men that IS null,
then queue is empty. So all the things we
have seen now notice, execute our program, build
compile current font. You can see noise out there. And if you, if you build and run your program to implement the queue using circular
linked list in C language. To insert into the lumen. Suppose I enter 20
again, I want to insert, supposed to insert an
element I entered as 55. If again I insert an enter one, then I'll enter 22. So if i'm, I will do
display or an Endo pool. Therefore you can see the
sequence domain D 5520 to 205522 is to split if you
wanted to delete there too, so you can see 20s deleted. So the element which
was inserted clauses, you need it very fast. If I wanted to delete
again and enter 55. So now 55 millimeter to the
family will enter three, the peak value it will return, so 22 is returned. So this is how we have
seen and for exiting, we will exit by entering fight. I'm done with complete
explanation of how to implement the queue using the circular linked list, as well as we have
executed the food. We have done executed
a board written in the C language as well as written in C plus plus language. And you can see how, if you can see it is very interesting and very
much Izzy digests, you should know, you should have a Via Veneto of the concepts of the queue and
circular linked list includes CES in
circular linked list, having on the button
pointer that is red. You can understand yes, how to reach to the
personal, non-linear. So all these things
are required. The concept you
should know so that the logic itself get
to know by using, by knowing the concept and by simply doing the program's
supposed to again, simply practice the logic on. You can do the
paperwork and then you can leave this program. Also increase of you
are thinking father, what logic you can do? You can simply see, yes, the logic of childhood didn't
whether it is same or not. If you want to check, you can simply
refer this program. You can simply copy
paste the same program, since I have made this available to you for C
language and for C plus, plus implementing
the queue using circular linked list so you
can easily access this code. I'm done for now. Thank you, friends.
Thanks a lot.
8. Circular Queue using Array Part1 session4: Welcome to the new session
of writing the program and executing for implementing a circular queue using the area, we will be writing
the program and executing and C and C plus plus code block ID for
Windows operating system. So first of all, let us see
what is this circular queue. And we will be
implementing it using the array stuff on What is this? Ok, you look, you know, the basic concepts of the cube, which we have seen in
our earlier session. First of all, we know that the insertion and deletion Athens and
different, different ends. Usually in social and
occurs at the red end and deletion occurs
adult friends that we have already
seen. Up to. Now, what is this
circular queue? And we know that in
case of the queue it follows people that is first-in, first-out, that is
the element which is until the host
will be deleted. First element which is
inserted last will be deleted. Lasso, this is how the
queue is maintained. And the thing about the vacuum, what makes the best
circular queue? First of all, we know that
the Q it is having ONE, that is the start end
and the last end. But n, which is visited
at the beginning, it's the beginning
of the last n, which is present at
the last position, that is the last ten. So when these beginning
and last ten, they meet at the same point, in that case it
makes it circular and that will name
this sulcular. Do this. Let me just show you the diagram on this circular queue here. If you see here, first
of all, the array, we known that indexing
starts from 0 and minus one. Therefore, you can see here, don't see the area. When we consider the RAC, this is 0, this is 1234567. Considering you are
having the area which is having the sizes. And therefore it is the indexing since
it's starting from 0, that would have ended seven. If you just see
here, first of all, if I just say that
the beginning and so the air is starting from the disposition
that is from 0, and it is ending at seven. So when you are beginning, this is the beginning
of the array. This is seven, this
one is the end of the beginning and
the end of the array needs wraps at the same point. You can see here this one. In that case it magically
appears as circular. Fact you can see your
circular shape here. Therefore, the name
is the circular cubed because we are implementing the queue using Larry and MEA, we will be constrained that the beginning of
the array that is, will be meeting the
end of the array so men can meet at the same point, then it forms a
so-called and therefore hence the reason the
name is ossicular cube. This only I had mentioned
here your board and meets at the same oil paint, same point, and so form the
circle, the circular queue. Now, first of all, some conditions which are there. So first of all, no more
condition you can see here is that if
you consider here. So normally we have seen, seen the Simple
Queue which we have implemented using an array
in an earlier session. What we have seen
whenever, first of all, we know that at front position
the deletion occurs at the front-end and the insertion
cause at the red end. First of all, why
does requirement of this alternate
Q comes into it? So you are already having the cube we have seen
using an editor. You have seen the purpose
of this arrival of the circular queue that
you have seen in men, we have implemented
the queue using an array that we're not read. It reaches the maximum position. If that air reaches
a maximum position. And if we wanted to insert, and we have already
seen that when red, which is maximum position that is ready just max minus one. In that case, we are
not inserting readjust, readjust giving the message
that we cannot insert. That is the reason,
even if we are having some backend positions in our array at the beginning or at the middle, in
that case also, we are not able to utilize if we implement you using the area because if the rarely just max minus one and that
is only the condition, this indicate that other
insertion cannot be possible in case of the
circular queue post-op, or even if they're rarely
just max minus one. Still, if there are back
in position, danced. And then in that case we can perform the
further insertion. We don't stop the insertion even embedded this
max minus one. So you'll even in fled revenue is max minus one we can utilize. It can cause huge. And so how all these things are
possible in circular queue. So what changes are
required in our program and what concepts we are you
should understand to get into. What is a board is all
about books, ocular cue. So first of all. What we will be doing is that the rare reaches
max minus one. And if you want to perform
further in search it, then we may simply reset 0. So we will not stop
the insertion. What we will do, we will see if red is equal to max minus one. And if you want to do
further insertion, then we will simply reset to 0 so that we can
perform the insertion. So then the next
insertion which happens, will happen and 0 at the rare position that
is 0. And then so on. We will be performing
the insertion operator. And so this is how this
changes is required. One changes required and not. Another thing is
even if your plank also reaches max minus one. If you want to delete
any instance, you, in that case, it is possible you have to simply reset
your front to 0. This is how you have to make
changes in your program. So let us see some examples of insertion and deletion
operations so that you can understand what all
things are possible, what operations, the operations of insertion and deletion. So we will take one area and we will it one-by-one element. And we will consider
some particular size because we know that arrays, so here the memory is allocated
for the size is fixed. You cannot change the size. And in this manner,
we will insert one by one the
element in the array, and we will also delete. And we will see these
things which I have talked about that when current
reaches to max minus one, rare it is to max minus one
and all different things, how it comes into it turn how the insertion and deletion happens considering
all these points. So just I have made one
now document in which I have written all the steps of the insertion and
deletion in case of this, a queue using an array. So here are just
considered this example. That is, you are
having first of all, the areas of total
number of sites or SD. Therefore, it is
having three sides. That means you can insert from the indexing starts
from 0 to 012, since this is an EDI,
therefore considered, we will be inserting the elements of having
the elements on the data type of
integer on the limits on the lobby of the
datatype in detail. Now, initially, you can understand now that we
are having the audio of size three there for
indexing 0 to two. Initially this this
queue is empty. Implementing queue
using a circular queue, using Alice with a
circular queue is empty. So what conditioners
there in case of that? When this acrylic is empty, that gives the
front will be minus one and it will be minus one. This is my initial condition. Now when we add inserting, we want to insert 102030, all these three values, we have to insert one by one. So we know that whenever
we do insertion, then we have to, we will be dealing with
when we delete and we will do these things we have already seen when we are doing insertion operation
will deal with the red. So in that case how to do a, how to simply insert
the element first, we will increment the read
and then we will insert. So that is first
of all minus one. So there will be
incremented by one, so red becomes 0, and then we will insert ten. Again, you have to insert 20. So when we'll increment by one mode value and therefore
red is equal to one. And then we will
insert the value 20. And then again we have
fines or penalties. So therefore we will increment, rear from one to two. It gets incremented. And then we will insert the
element that is part D here. And I have already
written those steps. In each element you, once I'm done, then
ten is inserted. That case, these things
have been done is I've just mentioned the steps
when we are inserting ten, then front becomes 0, red becomes 010 is inserted. Again, we uncertain quantity. Then this spread
gets incremented by one and then 20s inserted again. Third 30 we are, the rare gets
incremented by one. So here only I've
written next 20s and so did in front
the 0 becomes one. Thirties inserted front is same actually that is 0 and
read it becomes two. So initially when
the queue is empty, and then you add inserting
the very first element. And then with dread, the front also gets implemented that is at each
element accuse him, and then you're inserting. And only in that
case the frantic also gets incremented
with a red. But with the next insertion, we have to be as it is but reliability agreement with and then we'll be inserting
the elements. It's like this nightmare and these uncertain,
My friend is same, that is inserted, front is same, that is 0, but red
is implemented. Important thing
about this is that you can see we have considered the array of the size type DNR, this remedy, remedy riches. There, there's there being utilized with all these values. Now your array is full. You can see the size of the
array considered as three. So 012 index all these
elements are filled so you're sizes for here
you can see your Rare, Rare has reached to two. So that is the second
index, two index. Now, if you have to insert some, in that case, what will happen? First of all, you can consider manual cube will be
full menu or front. You can see here in this
statement of this view has become this condition. Finally, mentality got inserted. Then finally, you're all
anime and all events are, you're all alone at a
whole area is utilized. Therefore, the front
is 0 and red is two. You can find this 0 and red. It's true that when you can
consider the financial menu, you will be fully
manual practice simply 0 and your red
is max minus one. So this foundation you
can consider is full. You can see here in the queue is full all the elements
you have failed. So therefore, what is this? In that case, parenthesis and Redis through
the parentheses, there will be
maximized as month. Then you can consider
your q is something like, you know, next we will consider the other operation
that is believed. So we know that under
deletion happens, it will happen at the front-end. So what does your product?
Placebo and red is true. So therefore, little hair Bill had been this Depo
ten will be deleted, and then Frank will
be incremented. So than ten gets deleted, then Frank will be one and the same which was earlier that is maximized when
the disposal plant, this one and I
mentioned this one. So when this gets deleted again, then again, other Opry charts showing you different
different options. So when under operational pupil, insert 60 in this,
what will happen? First of all, we know in
N7 session happens to be up to deal with bread
and deletion happens. We have to deal with the
second position that is here. And whenever you want to insert, will inserted and so forth, so-called SPF seen in case of this ocular cue when rare
reaches to max minus one. And then other further
insertion we have to do. In that case, we will
simply reset to 0. We will not stop the insertion, but we will in
case of the queue, if you implement a queue, you have stopped in social
and religious max minus one. And so that would spend
you will not be utilized. But in case of the
solid circular queue, if you rarely reaches
here to max minus one, if you have to perform
further in social instead, you can fo form because it will set 0 and therefore at that please you can
insert your elements. So in similar in
this suck in case of this example also
circular queue. Red has already reached or max minus one and UI inserting 60. So therefore this red will be resetting to 016
will be inserted. So 0th index, this 60 value
you can see here is inserted. The venue in play your role
at eight, then the 162030, all these elements
will be split in this sequence manner
from 0 to n minus one. Now this only
inserting 60 will have been your ad against you sit and frankness in advance so you
can see all these things. So this is the difference
in the skew and the succulent you in case of cube and rarely just
maximize this month, you will stop further insertion. But in case of circular queue, if you are really
just max minus one, in that case, the red will be the setting to 0 and further
insertion as possible. In case of the circular queue. We have all the associated. Also, if you see
here now in this, in this case, the whole
area is occupied. This area, which is that it is. What condition you can see here. What is this condition
where you can see here possible that you are adding
a circular queue is filled, is full, completely, it is full. You can see here. In this case, first of all, you are rare, is equal to 0 in front is one. Therefore, if you see
here, trend is equal, that means the front
is equal to plus one. This condition it has, you can see here described
is equal to n plus one. In that case, your whole
circular queue is full, is unconditioned and what
earlier conditioned me. I'm also seen when was the secular view filled when
trying to 0 and 3ds Max minus one in that case
also the circular queue was spelled that is in this
example you can see here. This is one example in one
more condition we have to add on this violin showing so that we can then
rewrite a program. All these things we
have given to mine, what condition mutual friend
is equal to read last month. What is your front heel? Fall trunk is one and red is 0. You can see here front is 10, therefore friends is
equal to plus one. In that case, you can see the whole cuz occupy it is full. This condition also we have
to put panda queue is full. Now when we perform
deletion operation, you know that initially
the retina amino that Redis 01 when we
perform deletion. Then this one actually
first of all, this will be the element
that is 20 will be here. That is at index one. That is fun, that is
20 will be deleted and your friend gets
incremented by one. So if R1 becomes two
and the red is same, which was there earlier also
that is 0. That acetyl. But the front gets too actually. So therefore, you can see here, you can see a debt is 0. That is, this one in front is
equal to that is this one. Now if you again delete this, then what will happen since
wherever the plant is dead, that element would
it be deleted. So France is equal to
two, that is this one. So the element at index two
is which one is Thursday. This Thursday will
be deleted and post of n Also the plant
will be run becomes, you can see here, first of all, the condition that is
front is equal to two. That is plant is equal
to max minus one. And you are performing
the other deletion. So we know we have seen, we have discussed about
that vendor friend reaches max minus one and we have
to focus in Swiss franc. We deal with insertion
or deletion. We found we needed the deletions of wealth,
either revision, what will happen this plant, since it's reached
max minus one, it will be resetting to 0. And then in this manner,
deletion operation happens. So this study was
participant ID will be returned and the current
becomes receptor consider, frankly is equal to 0. You can see here, front is to 0. They have mentioned, and
your red is already 0. So you can see here
front is equal to 0. And here you can see that is also equal to 0 that span
the same and read and read. Both of them are safe and 0 if you fall form the
deletion operation. So you can see here that the cost of all
discipline and grad, both of them are team. That is, they are
equal and you can see here only one
element this lab. Simply check this condition
that one element, if you've performed that is
only one element in books, ocular q and the p for
pump deletion operation. In that case that
one element will be deleted and in that case, what you will be doing, you will not increment
your position me know, and then we'll return
me will simply delete that element and
friend gets incremented. But this behaviour we will
be changing in case of the circular using EDI men. And so what we will check
on that and check if only one element is left and if you perform deletion operation, in that case will not
implement the plan. But we will reset
Trenton rare minus one. That will, will
make it as empty Q. In that case, since
then we delete only one element which
is left in the queue, then element, then
cubicles empty back. In that case, we will
not incremented by one. We will listen to minus one. So this is what the conditions
which I have mentioned, you haven't read and fantastic. Well then only that means
only one element left. You can see a friend is also 0, is also 0, there is also 0 and only one element left at is 50. And if you wanted to
delete that agreement, then you will receive
friend and minus one. So here it's the
same thing when ran in front like welding only
one element left and so further delete occurs when fantastic non-French
not equal to minus one. Then also one more thing, as I told that,
that becomes equal. That means only one
element left in the tube. And when you wanted
to delete that only one and then you need to, you will delete that
element and usually sit front and then two minus one. But provided content, read our scene and when
you want to delete, but you have to ignore that condition when your
client is minus one. If your friend is minus one, initial spaniel
practice minus one. We have seen that when you
are circular queue is empty, in that case
parenthesis minus one. Also there is minus one. And in that case front-end
where vote on them or minus one in each
circular queue is empty. That means, and they are saying, because both of
them are minus one. So that condition,
you have to ignore. That condition is
not applied here. You have to always consider
that ignore that condition. In Italy, when the
circular queue is empty, we know that current
and network got them are same because both
of them are minus one. In that case, menu simply then you have
to ignore that case. Decided that case,
just leave that case. If that is not the case, if your parent is not minus one, you have to also
check that condition. And in the end then
also with that when front-end rarer
equals naught minus one, that means that is
also not minus one, but that means spent
in red are having same values but they
are not going as one. In that case, when
we perform deletion, we've been simply delete
that element and we will reset random there to minus one. So this is what I
have written here. I will show you
understood my point and also the programming.
We will see the same thing. So I've written these
metadata in front, all these when the
plant is not minus one, then in that case we will
simply not increment. That means we will say that
for this MDP don't increment. That means when. If you don't perform
the instrumentation on the front after
deleting the element. In that case, this
foundation front is equal to n plus one. It loads are not
having this condition. We will not call checkme and deleting data is 4D will not
check for the empty queue. So all these things I've
just mentioned here, you can just go through it once. Going through this session for
your reference, reference. One more thing that whenever, finally, your queue is empty, then finally for queue is empty, we will not check the
condition front is equal to plus one
because this will not happen because we have seen that one only an event was left
and we wanted to delete it. In that case, we
have not incremented by one and that's what this
condition did not arrive. And therefore, only the
condition to check when the circular queue is empty only we are protected when
current is minus one, then only you can show that circular queue
is empty otherwise, there is no other
condition that will make sure that the
circular use empty. That is, this condition
will not have to not take this condition
because we will not increment the front if
only one element left in the queue simply reset
front-end relative minus one. So this is all about some
conditions which are required. Now, finally, we will
check this condition. That is a plant is
equal to minus one, then the circular
queue is empty. For circular queues, for me, check this condition
in parentheses equal equal to plus one. Or friend is equal
to 0 and where is max minus one in that case
also your circular queue. But when Frank is
equal to minus one, in that case, that is this one, the circular queue is empty. These all conditions
we have protected. And if you poke on the
fatherly lead, first of all, this we know in this case, what is the condition both front and rear,
they are equal to 0. In that case, if we wanted
to simply delete again, what will be the case
when this is deleted? Again, 50 is deleted
as 50 will be deleted, and therefore, nothing is set
in front and two minus one. Therefore, this is the thing. Again, if you perform, again when you fork
on the insertion, then you know that whenever
you perform in social media, we'll talk with, we
will deal with rare, so rare, so there becomes 0 and we will
insert the elements. So therefore address 0. You can see here
this 90 elements in sorted all these services. What about the ERPO
insertion and deletion? So we have seen till now that whenever we want to pop on
the deletion operation, and if the primary
just to max minus one. In that case, when we want
to perform further deletion. In that case we're doing
simply received from 0. Even if people
home the insertion elements and the revenues
is max minus one, then we have to reset the serum. Then, in the case when q is only having
sunblock is having only one element in which the India not in which
arguments event, whether you having only
one eliminate both of them are equal but not
equal to minus one. In that case, only
one element present. And to delete it, you have to simply believe
that element and you have received your friend
where to minus one, and you cannot
increment the friends. So all these things, I
have already mentioned what all operations you can perform and how it will be maintaining
your circular queue. So I hope you understood
many points out of this. Now, as I also told, you, just let us write
the program and execute it in the
Windows operating system using C and C plus plus.
9. Circular Queue using Array Part2 session5Lecture1: I had mentioned here the
purpose of the circular queue. First of all, we have seen what are the disadvantages
when we implement the queue using area that we can position we cannot utilize efficiently even utilize
a pitcher entry, rarely just max minus one. So that is the reason
the circular queue comes into picture, that we'll be implementing
it using EDI and enriched. Even if they're
reaches max minus one, it does not, I did not stop. In solution, it
will reset to be, rarely gets reset it England
and against reset to 0. And insertion is possible even if current reaches
maximum minus one, then deletion is still possible
as plant gets reset to 0. So this is how it allows
insertion and deletion and on. So that is a name
circular queue. And it is how it, you
realize this that I can position which is there
and therefore it is. Therefore there is no
base staged OK memory. This is how we have seen to now the example on so
we have considered. So let's move on to
the code block ID. When I have created the project. What's ocular? You're using EDI and vote. C language and
sweetness, C plus plus. So two projects we
need to create, so I hope so you have
installed the block ID, it's very easily, I believe
in you can sleep download it. Simple steps to install
it so that you can directly write the program
with me and execute. The anonymous. Already did the full deck. I have written the same
program in both languages, C and C plus plus which VDC program in C plus plus language
will execute it. Then we will see the other
project which I have created for the same program and C language and
we will execute it. And also I have shared these sources called source with you so that you
can easily access it. You can copy paste and also
run at your end, so forth. Let's see the classes. This is the how to create a new project
I've already mentioned. Always click on File, then you're in the
code block ID, then Project, and click
on Console Application, then click on Next. And then there are two options. Seal in enthalpy, want to write a program in C language,
you can click that. If you have to write the
program C plus plus. And since the scanner
reject machine, it'll be seen first
will be in C plus plus. C plus, initially
conceived plus, plus. And then next. And just write their name on
the chart, meaningful name. And then you can proceed
by clicking on Next. So this is how I created a new project for emptied
Plus Plus language. Now let's see the glass which
is there for this program. First of all, you have to
declare all these identifiers. I was streaming on these
things and I have defined since I've been implementing this circular given using EDI. So I have defined the
size as 30 suggests. You can just change this size depending
upon your requirement. I will show you the example, the same example I
have considered. It's shown you in the document. I have considered
the same example. We execute the same program. I'm saying Mum, example, which I have shown now
that we are considering the U using the EDI and we'll
consider the size is three. So indexing starting
from 0 to 2012, the same example
we will pick here. That is the reason I
have defined the size of the eddy as in, you will be using
this namespace std and gives us C Plus
Plus language. And this class is that
which I have defined. So if you look at it, what is that in this class? But shuffle, you are having the constructed and you ought to, and you are having
this front end. What does this front-end reds. So first of all, I'm having
the public access specifier. I'm having this constructor destructed and all the
functions as public. Functions as public
and private access specify in this class. But in all these variables
are private goods which are data from which we are using, since we will be implementing the queue using the
circular curve using areas. So I use this area for that. Now this phantom read, I have declared as private. So this indice constructor,
I have Initiative. This constructed, I've
initialized Is Brandon rare to be minus one because
initially you are circular, queue is empty and the
condition is that you have to, in that case the front-end read both of them are minus one. So that is a reason and it's constructed and then
this function Q. And so that is used to insert the element in your
circular queue. You delete it is used to delete the element in the
circular queue, peek to return the value in this regular
duties flavors split all the elements of
the circular queue to check whether your
queue is empty or not, then a skillful pull to check whether your
queue is full or not. Now, this stone and all these
functions which I have. Mentioned here, insert or
delete being displayed, EMT, EMT, all these I have
defined outside the Cloud. So that is the
reason I mentioned the name on diagnostic
or resolution. This function name, that is a member function name of the class which I have
defined outside the glass. We have to give the name of the class scope resolution
manually finance in class. And on this instructions, logic for each function
is still empty. Then q insert on this logic
which I have written here. Then q delete, Display
and all these things. Now coming when you
execute your program, the control pumps in
this main function in C plus plus language
and one by one, all these instructions will be executed in sequence
order, line by line. So first of all, this display
message I have given, let me just add one more thing. This spiritual, what is the
main purpose on the program? I have just given us in
Buddhist agreements age when it uses an execute the
program to implement. If you look you using EDI. Now, these variables
which are declared agency helped me feel software
and this you can, since we have to call them member functions
from the main function, that is, I will try
the, therefore, I have created the static
object of the class. We can see the name of the class are static object,
that is Q edit. Now for by this object I will call the functions from
this main function. Now, since I have four index, since the user should
have the provision, the options, didn't they
use it on one to exit? A number of times user can
give different options. The user don't want to exit. That is the reason we are taking the infinite loop
by using vitamin. User wants to exit. Then we add also
providing me that option because there should be a
terminating condition also, you should avoid the program will do the infinite
loop the future to get some stock condition wherein
control comes out of this. Now that is a reasoning are getting this option
five is extra, so different options
are there which will be displayed and users
can enter one on them. Any of them. Insertion, deletion,
beak, display, all these abuser want to insert user will enter why we are using switch case when indeed the cell numbers which
are there, 12345. In symmetry, this option, this option is of data type
integer and this item, we insert any element. Then we now ask user
to enter the value and we collect in this
video we'll items we can see how we can use. So therefore, this option 12345 comes here,
and accordingly, these cases will get satisfied. That is, this case
will be executed. Suppose you're using an interval depending upon these options. One is foreign social user
wanted to insert that. We use a head and turn
on this option and B1. And this case we're going
to be executed and these instructions in being executed, and since it's a
brick depo control comes out of this case. And finally, comes out
of this switch case. Again uses giving me different options and
then this manner. So let us see one by one on the definition
of this function. So what is insertion in case of the circular
queue using edit? In that case, user
will enter one and this display
message will be there. Enter the limit to be inserted. User will enter an element. Any revenue that we're collecting
in this variable item. And we are calling this function Q is answered by this object, static object dot, since
it's a static object. And then the name
of the function and you're passing this item which values, which
user wants to him. So let us move to
the definition on the definition of the kilogram. If you'll see this given set, which is the name of the
classical presentation here, insert an item with user
entered on, on the country. Now first of all,
before insulting, so what all different
changes we have seen? First of all, when we are inserting in the
socket of UV or are we supposed to check whether your queue is full or not
in the queue is full. And that gives, I
don't know if I can foresee in your queue and then you are not supposed to insert any element because
overflow can occur. Therefore, this condition always you
have to be mentioned. Whenever you have been surgery, you have to check whether
the queue is full or not. What is this definition? I have defined here? You can see here. Thank you for what conditions
are required. So we have already seen in
this document or near I've shown you that there are two conditions which
is required to check. So you can see here
when I've inserted 102030, all the elements. In this case the
circular queue is full. There are no weekend
positions on that occupy. So what is that condition
when you are in this case, when it does you know and
reach to max minus one. So this one condition
is dead. Will check. First of all, debt will enter your full when this
condition is reached. Deafness or few circular useful. In normal condition,
we have checked that is men front is
equal to plus one. You can see here the red
is 0 and from this one, so they visited, Let's walk. And therefore this
condition also in this condition though you can see all circular queue is full. These two conditions
we will put. Therefore, skillful
Wealthfront is equal to 0 and
random x minus one. This is one condition which ensure that your
circulant useful. And another condition that we are primed is equal
to that plus one, then you sub, you
know, queue is full. So in that case, if this condition is dead,
then it will return one. That means q is not satisfied, it means it will return 0. This is how we below checking the condition
for beautiful. Now been conditioned. We have checked that
it does circular, useful than what
we're supposed to do. Then another condition in
each Ellie and us empty. Then you want to insert, then in that case your
friend is minus one. So first of all, we know that whenever we are
inserting any element, we have to deal with rare. But when you are inserting any element and
initially, you know, initially your circular queue is empty and you need to
insert any albumin, then you have to deal
also with client. Along with the red. You have to deal with trunk. The venue odd. Then for circular queue
is empty, you insert, In that case a friend is equal, equal to minus one n two
circular queue is empty, then you have to increment
the friend by one. So trying to is equal to 0. So this will be on the manual
circular queue is empty, otherwise venue or there's
some elements present in kilo Q2 and you want to insert and you
will need to touch. You need to deal with
the front on that arrow, then reaches max minus one, then you will not
stop insertion. You will continue in
solution and therefore you will reset that to 0 in case of the subclavian decided
advantage which should own the circular queue provides this is gonna be itching
or have given here. If this is not defined region that has not
reached max minus one, the normal steps which
are insert first, you will increment it by one. Then later, after
all these texts and accordingly the
execution takes place. Then you will insert the
element which user has entered, and you will store it in
your airways to this item. And then in this
index this is adding, this item will be inserted. This is how we have this. This is a definition
of insertion. Now, moving through
the another option. If users, that is user want to delete and
case two will be executed. We are calling this
bystander with object. We're calling this function
that is skewed deleted. It will return the
item which is deleted. So definitely can see
here item and we know this item is on the
datatype integer. Datatype integer. Now, let us see what is this definition of
whiskey or delete. First of all, it will
return the integer. This is the definition
of Q delete. Here outside the
class we're defining, not having any arguments. So here, first of all, whenever we are performing the denuding any element
from the queue, whatever Q it is something to look forward any type of vacuum, we have to always check whether the queue is empty or not. If it does, queue is empty, that means there are no
elements present in the queue. There is no question to delete. So that is a reason for Stephen and charter that
you'll queue is empty. How to check whether
queue is empty? We have already seen there is only one condition when
the queue is empty, when Francis minus one. You see here, we have checked only one condition
in front is minus one, then only it will return one definite security
empty as it returns 0. This is only a simple condition
used to check whether the accused is empty and if he was emptied and this message
will be displayed. If not empty. Well,
and good weekend. Proceed to delete any aluminum
from the circular queue. We delete elements
from so beautiful. Now, we know that whenever we had to delete any eliminated them
circular view, we have to deal with the front. So first of all,
at the front index what value is present
in the array we will collect in the variable item. This item is of datatype
integer so that you can see a Q and a school Daddy
and the spanked index, simply collecting the data
format from this index. And then there are different,
different conditions. Now what are the
different conditions? So first of all, we have seen Whenever of non-linear check the condition when
the queue is empty, what we're supposed
to do, if there is only one element present in
the queue we have seen here. You can see here in this document I have shown
you whenever there is only one element
left in the queue and unique to delete
that one element, only one element, which is this is only
the one condition, is a condition when
only one element is left and human
you want to delete. Then what things are
required when you delete this only one element left in the circular queue
and then there will be no element present. So in that case, you don't
need to increment your friend. You'll need to simply reset your front and that minus one. That is a reason this I have already shown
you in this document. So therefore, you
can see here we have seen when this fifties there, there is only one element in this circular queue and you
need to read only and human. In that case, we are
simply resetting the trunk and rare minus one. Therefore rho,
therefore, you have seen here that though initially, in this case, this condition, this is g actually. And you will need to, you need to delete in this 50 element which is
there in the circular queue. And therefore Wendy
for Hong bleed, in that case, it
will be deleted. That is this one. That photo you can see
here we have seen in this document itself whenever that is uneven and he went left, that is 60 in
circular queue here. First of all, when we perform
a delete operation on this, on this circular ON cubed, which is having on these 60. In that case. When we delete this 60, then there will be no elements. In that is, we will be not
incrementing different, but we will, in this front-end, rare to minus one. So this is the steps, this is the change. If you complete the circular
queue with that cognitive, do you mister you have seen in an earlier session in case of Q, we had seen that whenever we are deleting only one element and then we need to
simply increment front. But here in case
of circular queue, we need to reset front-end
rare to minus one. You don't need to
increment the bank. Therefore, this plant and
becomes minus one in that case. So this is a change
which you have to note. So this condition on the, we have put in order logic because all
their different condition, you have jack van
that he was empty. What you are supposed
Studio supposed to do when this Brian
ten bread, if it is. First of all, what
condition is there when only one element is
left in the queue? So you can see here, only one
element is left in vacuum. So in that case, we have seen this Frank is 0 and
red is 0 in that case, that means both of
them are equal. But we have to also
ensure that in that case, the front is not minus one. Because we know in case is minus one condition is only there when you are circular
queue is empty. That condition we have
already checked earlier. First of all, that is, we have checked when nerves, whether the queue
is empty or not. So KMT what it is
checking it as checking whether the plant is minus one. If it is one minus one, then we will be accordingly
take different action will be exhibiting that condition we have
already checked. So therefore directly, when you check this
condition rather front-end, front-end there
are equal or not. In fact, Giza Franklin won't
be equal to minus one, but it's going to be
some different value. You can see here. Because at that, that
condition only we have simply the reset
current and minus one. So Ben Franklin, what is the condition of only one
element left in the queue? Condition is that the front you can see and read
both of them are 0, that is, both of them are same. That is, these. And I have
given this condition. If front-end read both
of them are equal, then on DBS opposed to reset the front-end
bird flu minus one, then only it will ensure
that both of them are equal. That means only
one element left. And then in the queue which
you need to delete that both. We have already posted whole
story here in each earlier than the value at the
front of the front end. This video we'll item so we will reset this run ten
raised to minus one. Yet I've written
here the message. It has a comment, only one item left in the circular queue. And so do you think it
we said that we have, we have pretty simply recent
content read to minus one. Now, this condition we have checked reaches max minus one. We have also seen that if your client reaches
max minus one, then in that case, if you want to delete elements from the circular
queue, you don't, you can not stop deleting
even if this max minus one. Since because you will be
setting the front to 0, then that is a reason. This is the advantage
of if you like you, that if the red also
reaches max minus one on the front reaches
max minus one, then in that case you will
reset front-end lead to 0. So here, first of all, we are dealing with religion. That will be, we'll talk about
the front and not break. If the parent reaches
max minus one, then you have, you will
not stop the deletion, you will simply
dessert plan to 0 and then this manner you will
perform the deletion. Now, that means in
the normal condition, when what steps you have to do since you have already
stored item in this manner, then you will simply the
normal steps you will implement the front via this. And then finally, you will
return the item which you have collected in this
variable initially. This is how this is the definition on the delete
and the circular queue. And you have understood
what changes are required as if you
compare it with the q. Now, let's see
different functions. If the user wanted to perform, peak user will
enter three scales. Three will be executed. That is just our message. Peak value is of
metastatic conflict. I'm calling this peak function. So let us either definition
of the speed function. You can see here the control
comes here and here. First of all, since we will
return the front value first, we will check whether your
queue is empty or not, because if the queue is empty, there is no point of returning
the front from the Q. Therefore, you will check
whether queue is empty. And we have seen what
is their definition is through MTV objective time, this minus one equal
equal to minus one. Then it means the
queue is empty. So that condition when
tag and then we links it. Since the middle not perform, we will not return any value. There is no element
in the circular hue. So this condition, we have
to check initially if this condition is
not satisfied melon, we will simply return. We will return simply the
element which is present in this front index from
the circular queue. Therefore, we will return the front value from this
Eddy in case of the peak. Now let us see what about the user enter
different options. If he was going to enter for, then that is four
to display them.
10. Circular Queue using Array Part2 session5Lecture2: Uppercase forward
will be executed. That means the user
wanted to display all the elements from
under the circular queue. How you're calling
this display function. You are simply by
the static object. You will be calling
this display function. So what is the definition
of display function? So this is the definition
control comes here. First of all, you need to check whether your queue
is empty or not. Because if the queue is empty, there will be no elements
and circular queue and then there is no
question to display the elements if there
are no elementary. First you have to
check this condition. If this is not satisfied
well and good, the current instruction,
it will not execute. And therefore this
display message, you elements are and then the frame conditions of water displaying
all the elements. So first of all, this
thing is different if you therefore
different fund each inside there to display
all the elements. So just check. Please. Just therefore you can see here we are using if condition and
as garden region. So what does this if
condition, an else condition, if condition I have just
displayed this message, display the elements in-between. If your friend, if it
is less or equal to, means if your plant is having the index which is
less or equal to. In that case, you will display all the elements
which are there. In that case, you will display all the elements
which are there in between the trunk and the front is less or equal to
because we built, since we have to display all the elements in
the sequence wise, that when we are
checking this condition. So when Frank is less
than or equal to means, there are elements present from frontal red and that
we need to display. And simply in that case, since in Italy I've
collected before elected the index of the
plant and medieval at this I, this iss of the
datatype integer. So therefore from this, I will have the
index of the plant. So that is a reason. You see here we
have checking posts in front is less
or equal to red if it is less than the EPA display all the elements which are
starting from frontal red. Therefore, this
while-loop quantile I have used, what is
the slide like? Lupus IS fast as having
the index of the current and that people aren't
displaying all the elements. Reaches to read. Because we have to display all the limits from between 910. I'm from the index
of the frontal red. You can see here C-out, I'm using an in-display, this Q Eddie, and in that case I'm doing the post decrement. I'm display impulse decrement
teaching phonics element is will be printed and then implementation
takes place later. This all elements
will be printed till your eye becomes
equal to prayer. So that means all the
elements which are there between front-end dreamt
that will be displayed. And these are the only
elements which are present. There are no other elements
present in the queue. This condition is not satisfied. That means if current
is greater than bread and that is this condition
will not be satisfied, else will be executed. So in that case, if your friend is
greater than red, you can understand in that
case what will happen. First of all, that means you are having the index which
is lesser than that. You can understand
that in that case, we are supposed to display the elements which is prompt 0, that is from 0 index still rare because if the read is less
than r1, so therefore, if you see here, is
equal to 0 and tract is equal to one in this
case, could add a 0. And trying this one. That means the rare, then you can see what
we're supposed to do. We are supposed to
forestall print all these elements
which are present in the circular queue and Rome
in each from the beginning. And therefore to that
point you can see here, since this brand is
this lattice having the index 0 and friend
is having this one. So first of all, we will display the animal from 0 to read. In that case on me. In that case, we'll
start the indexing. We start, let us reason here. You can see this else condition
where the red is lesser than that intuited cost. You will display the elements. You will reset your eye to 0, from 0 till you reach Europe or display that
all the elements. So first of all, we
are here at read only, so only 60 will be displayed
in this period here, host in this while loop. You can see here. Then later, we will be simply starting
from the Frank index, still max minus one. So you can see here again, this IS reset it to front value. Then this, begin this
one more while loop. And then we have written if I is less or equal to max
minus 11 by one, we're displaying the elements of the circular tube and
we are incrementing the I hope so you understood how to display the elements when you are rare is lesser than friends. So here, this example that
I'm showing because this is fulfilled in our document and this will help
you to understand is, first of all, if you
are rare in turn. So first of all, it can happen that Q is of
size five and anything, he'll be considered a
small, circular queue. But if it is often
cited Stan or what? In that case, if your red
is having the index two in front is having the
index for that case, red is lesser than France
when that is positive, all we will display the
alignment from 0 to rare, and then we set the
value to front, and then we will again expand humans wrong time till we reach the end of
your SOC colloquium. So this is the
condition for that. If that error is
lesser than track and if it is greater than Frank, that is front is having lesser
value or equal to that. We will simply this
other elements which are there between Frank and I hope you understood what is the
logic and in this split, in this manner industry
on the limits. We said then this
circular queue, this is the definition, no. If the user enter five, that is to exert
case five will be executed and simply exit
function will be called. The user don't enter
from one to five, default will be executed. That is the invalid option is user will get this
display message. These things are there. So we have almost seen
all the things which are there in a program
in C plus plus language. Now let's execute our
program. So how to execute? Just click on in
your current file. When you compile your file, you will see the belongs here, whether there are some arrows
on occupancy and blocks. I'm not getting any errors,
yellow arrows wanting. So how I get these laws, Simple View and
check on this loss, this message, it will
give you this block. And here you will see
rather than edit, edit our present or not. So here we are not having any
error well and good we are, we can simply run our program
by clicking on Dillon run. And then you will
get your console, the display message
programmed to implement circular queue using arrays,
these different options. So suppose I am, I will consider the same
thing which is HBR doing. Let us see the same. So what initially upfront and rare is minus one when the
queue is empty, then we're inserting
102030 minutes. Insert these three U's, and we have already
taken the sizes of the error in our code. We have defined the size of the areas you can define
any ASI is just to make you understand
his VM taking the same example,
I'll insert 102030. Now, I'll click on 1 insertion, then enter the limit to be
inserted and entertain again, I'll click on one to
Insert, and then 20. Suppose I insert,
again one to insert. I'll enter three values
I have inserted. And if I click on full, display me ten to 30, all these three elements. Now, let us see different
operation like let us delete. If we delete the first element which wasn't circuit
should guarantee v8, Let us for deletion, you have to click Enter to. Therefore, you can
see here sees me and deleted item is tensor has donated the
very first element. Take an input notice as it
is dead, but ten is deleted. Now again, we will insert 60. Now, if you have seen here that red have already
reached max minus one. Now even again, perform
the insertion and we will see whether the circular
queue is allowing or not. We have seen in
circular cuban refuges max minus one, it should be. In order to insert, let us
see it is allowing me or not, even if it reaches
max minus one, if it is allowing
you, that means up. Our coding is correct, which is therefore
circular queue. So let me click
on one insertion. It asked me to, and even suppose I enter 60
or UPC and it has not given me an error saying it cannot
insert or some message. Now let us see what
values are inserted. You can see here 602030. That means it allowed
me or inserting this 60 here even if there
was max minus one. So this is the changes which we have required to
do in the circular queue. And this is the advantage
that packaged foods each are not occupied even if
the red is minus one. So 16 does it displaying in sequence for 1620 and then 30. This is how this happens. Menu perform the deletion. In fact case what will happen? First of all, many liter happens the front index
meditative, but it is present. It should delete that element, so was this one. So therefore should
you need to enter. So if you just go and put on, then it has deleted 20. That is correct. Between p and finally,
after this delete, it looks like this,
that certainly is deleted and 60 does
days was typed 11. And again, you perform delete. Click on 12, then tattoos also, believe it that is, it
has to repeat our DNA. It looks like this on
the 16th president. Now again, when you delete
that case, you perform delete. Then new element will
be presented as this. 60 will be deleted by plant
in red will be minus one. Let us click on
delete, right-click. Again, it has deleted 16
there is in this manner. Now when you insert
90, in that case, your content will be incremented
from minus one to 0, then 90 will be inserted. So if you click on one and if you enter the element
as 90, you can unmute. Employee, you will get
this element is 90. So this is how we have
seen the same example. Now if you want to
display this peak value, you will get this 90 or knee
because there is only one way present there is a defined, it will return that value. Tremendous having the index 0. So at 0 indexes
nineties present, it will return this value. And manual to display. You have already seen
different options not to exit or enter pipe. This is my how it has
exited the program. We have seen the program
in the C plus plus nine, which has seen the
complete program. Now let us see also there. Now let us see the
program in C line. Let us see the same
programming language also. And for that you need
to foster called LIATE, create a new project I
have already created. Just to show you, I am
showing you File New then project and then
console application. Next. Then you have to click on C and then click on Next
menu, click on Next. You have to give the name on the short name and then
you have to click on Next. This is how you will create
a new project in C language. And you will write
the same code, but the syntax
will be different. If you compare that
with the C plus plus, there will be no
class present in the C language and you don't need to create a static object. First of all, these other
header files which you need to include iodo
attach or colleague. If you call print F
Skinner function, then you have to define. So I'm using the same example
of that of the Eddie. So that's what I'm
giving the sizes the same porters that only
some syntax differences. So all these functions
and variables I have declared outside
the main function. These functions are defined outside the mean
function globally, and these variables are there. In Italy, we have visited friend Andres minus one minute of
circular queue is empty. And this is the EDI Mexico. Same thing was just a defense in front of the main function. When you execute your program. Instructions will be executed
line by line in sequence, or the support unit displayed this message on the console. Just to make up what is the
purpose of your program. You are implementing
circular queue using EDI and these same things which we
have used in cplusplus, these option item and this
vitamin infinite loop. You are having switch
case running in this infinite loop
and you're providing different options
whenever you want to insert user to have to enter money anyway, I
want to believe so. You will use this switch
in all of these are on, these values will be entered in this variable option
and you are writing switch option and for any of these cases will be
executed the same thing. So in the case, first of all, in this main continue
directly calling function f, where you can see
here, you insert, we're not using not a
C plus plus program. Therefore, there are no class, there is no static object
that actually we can call this function as it is
Interbrand scanner. If these are the functions
which are used to display them as Satan scanf is used to take the input
from the console. In C language, we are asking
user to enter the animal, choose Insert in the queue. And this we are collecting
in this variable item. And we are calling you insert. And we're passing This item, which user on doing self and
what is their definition? The logic is saying that
we have already seen, first of all, when
we are inserting me up to check whether the
queue is full or not. If it is full, there
are no points and open sorting. This foundation. I have checked it and
I've exited school. So what is the condition
on this queue? Full poster for the condition we have already
seen when Frank is equal to max minus one that
I have already shown here. In this example, you can
simply see this condition. Men friend is equal to the integral of u
when it was full. Actually, all these elements, you can see all these positions are occupied or the
circular queue is full. If your friend is, max, is max minus one or
plus one, that is here. One more condition when you are, you can see your friend
is one and plus one. This is also one
condition variable, circular queue is full. So this condition
you need to check, then that will give you whether your circular
queues full or not. If not, well and good, you can insert so
you had to pause, see initially whether this is a subject ICU at
initial condition, that is when the
cyclic AMP is empty. Therefore, when the queue
is empty, main factors. First of all, when you
are trying to minus one, then in that case. First of all, whenever
we wanted to insert, as I told you, we
approve deal with rare. But at the initial condition except in the initial
condition and circular queue is
empty and we have to also deal with the Frank. So initially if your queue is empty and you want to
insert any element, then you have to check
whether it is minus one. If yes, then you have
to increment by one. So friend becomes 0. And if it is not, if it
is not initial condition, that is circular
queue is not empty in that case if red reaches
to maximize this one. So this is a changes
which we had seen in the circular cute rarely
just max minus one. And if we wanted to insert, it allows in social
and circular queue by making the read as
0, resetting 0. If this is a condition, that means you want to insert the element at
different position. In normal condition, you have
to increment it by one and then you have to add this
strategy lets you insert, you have to store this element, which user having the console, this is the definition
of insertion. And then if you observe from the main function if
he was an enter two, in that case, this deletion happens when the user
wanted to delete. The control comes here
in this function. Since we are calling
this function directly from the main function. And softball, we're checking
whether the queue is empty because if
the queue is empty, there is no point of deleting. There will be no
element in the queue. Therefore, we have to
check this condition. If you MTBE have simply checked whether the queue will be empty when you are
trying to say minus one, then I'll need to return
one as it will return 0. Simple condition to check
whether it is empty or not. And this display message, it'll be there that
you cannot delete because it undertook
condition cannot go. Flip it. This is not the condition. This is not satisfying
Wallenberg, that means you can
perform deletion first upon the very first
thing, what you will do. But because we know
whenever we want to delete, we will deal with the client. We will also call
collect the value. Just present at the index
plant, a trauma the areas. So this first line you
have to write here, that is the plant index. What element is
present is Eddie, you are collecting in this item that is the datatype integer. And then further operations you have to do because
other operations which accordingly you have to
David's book that you have collected the value item
from this plant index. Now you have to check
this condition in the same condition
which I've shown in C plus plus also a prime
dt is equal to read. This condition will
be there on the, whenever you are left, we don't need one element in the circular queue if
you want to delete now. The poster hall, in that case the front and read both
of them will be the same. And in that case of
families not minus one because you have already
checked your itself. Applause, please spend
the queue is empty, then only fund
will be minus one. So therefore, if this
condition is not satisfied, then only it has
control has come here. And that means our
plant is not minus one but front-end equal. In that case, as I told you, we want to delete them. We will be simply not
incrementing the front, as we have seen in
the queue in case of circular tube
will be resetting the plant and drag to minus
one as shown here in this. So therefore this
condition is important. You have to give, you have
to give manual Cumulus. Having a mnemonic circular queue is having only one element. This is not a condition. You have to check if
the plank reaches max minus one and
instead you can delete. You will research the farm to 0. And finally, these two
things are not there. Then also this is if,
it's if and else. So these things are not
satisfied then else that is the normal thing that you
are incrementing by one. And finally, you will return this item stored in
each allele only here. This is how this is their
definition under Delete. Now let us come to the main function and
see different options. So if the user entered, encase three will be
executed directly. We are calling the function. We are displaying that
and display message. What does this function let
us see the definition of it. This peak function,
first of all, in which we'll be checking costs if the
queue is empty because in the speed function
and we're done with this president at
the practice index. If your queue is empty,
there is no point, no elements in the queue. Therefore, you are not new and you cannot display
the planned value, the value at the front of index. So your project, this bandage
and when they appear as empty or not empty, then it will exit. If not empty, it will simply return the element which
is at the front index. This is what now in the
main function again, if you simply enter for dentist display function
will be called. So that means you're displaying all the elements in the cube. Therefore, what is our
definition on that? What are the reputation
of the display function which I have already shown
in C plus plus also, based upon human check whether the queue is empty,
queue is empty, that means no
elements is present, that means no point to split. Therefore, you have to check this condition and it
will enter and exit. If not in the queue
is not empty that some values are present and
you have to check different, different conditions.
So impulses used. First if condition,
you will have collected the index
of the client. In this video, we'll dive, which is the datatype
integer we have seen here. And then you have to check
if fences used first, if the plant is less
or equal to the plant is having the value which is
less than or equal to that, In that case, first of all, you have to display
all the elements starting from tranquil. Sequence order
Darrel, there will be all the elements present
between the front and grep, starting from tranquil dress. So you have to display that. Therefore, this while loop
is used and this condition, since I had eyes watch it is actually the
starting from trans. So it didn't you reach the
Display button by one. You can see you, I was
enforced in imitation. You are displaying the
value and the editor, and you are
incrementing the I one by one until you reach
this. So this is one thing. If what, It's vendor prime
is greater than red, that means is having the lesser value S compact to that of the
plant we have seen. In this case. You can see first of
all, the red is 0. And from this one
that means is having lesser value that
this has been index 0 and from this heavy index one. So in that case, since
we have the spleen, the supplements are done how you display cost of
quality from you. We'll set the value to 0 and you will start from
0 till you reach read. You have to deal with
display elements. Then you can reset this. I do read and you
will start from mom, that maximum us
start from plant, then max minus months. So this is the condition. So n else condition when the red is less than
front, first of all, you reset to 0 and
then you will do till you reach rarely
will display one by one all the elements
within Clementine. That point, then you can
research, I do, Frank. That is fine. Value will be assigned to y. And from junk value, Frank index till you
reach max minus one, you will display
all the elements. This is how you display
in the sequence. This is the complete logic
of VFC for insertion, deletion, cupful, circular, beautiful
circular queue empty. All these things. Now run our code by first compile
the code by clicking on, we'll compile current file. You can see, since I've
already compiled initially, let me just show you
your final current file. You can see no arrows are there. It comes in belongs then
building the building. So it'll pick the
same, same board. So we'll insert 11024 to
display the full 102030. Then we are supposed to do, we'll delete by clicking
on to afford to attend which was inserted
first will be deleted first. And that is deleted posts. At that point you are left with, if you display your, you're
left with 20 enthalpy. Now I will try to insert 60. You will know that red has
reached to maximise one VDC. By that it allows if I click on one and if I enter
the lumen and 60, an event therefore displaced. You can see here it allows
insertion or even 60602030. This is how it has displayed
me the elements total. Now we'll perform the deletion. So I'll perform to his 20s deleted we have
seen in our room. Then again, if I perform deletion and inter-group
disparities deleted, now only one element is left, so you would display port. You can see your elements 60. So again, if you delete
that funding ratio, the set to minus one and then Benito forming
social like 98. So it allow me to insertion by incrementing
front and register. Suppose let us delete by
clicking on Enter to delete it. You can see deleted item is 16. There are no elements, not if I click on one to
Insert and I insert 90. You can see here, if
I display full on, an element is inserted and if I enter three to four
performing the pKa position, they've been returned the
value end up front index. So therefore, if
you just click on I had clicked on to
the circuit and return the peak values to 90. So this is how we did it all. If I wanted to exit, I will click on Enter fire
and will be exempted. So this is how we have seen the company programs
written in the C language. You can see it's quite
interesting and logic, you have to understand
the concepts are the main motivation is the main thing which is required here is that first
of all, you know, you know the Q, how
to get into how to understand the
circular to just buy the concept pollution and
who should be on there. You should understand what
is the difference between the QN circular like you first, what a circular queue fissure
normally have seen in our presentation about
what a circular queue. And then what is the purpose of circular due to a wider
disadvantage in the queue, we use sub unit cube. That is to utilize them. I can position in the Adi we are using
the circular queue. That is a main requirement
of the circular queue. And what conditions
are required, right? Makes up yellow. We have seen all those things and what changes are required, what we should do in order to avoid or utilize if I can
position we are in certain. Trend indeed reaches
max minus one. And when I would want to insert and when
religious max minus one, we have seen we have
to desert there to 0. The Frank has reached max minus one and we want
to delete and we will collect the item and then
we will simply reset to 0. And we have also
seen if only one M here perform division and
only one element is left, then what changes are required? You collected item delete. He did and we would
simply recent trend and where to minus one. So all these different
things we have to have to do in a circular queue using
the editor. I'm complete. I'm done with some heat session on writing the program and
executing the program for implementing the
circular queue using the EDI and T language SLS C plus plus we have written for
Windows operating systems, so let's meet in
the next session. Thank you. Thanks a lot.
11. Deque using Circular Array QueueSession6Lecture1: Hi, welcome to the new session of writing the
program and executing the human structure using
the circular area in both the language C as well as C plus plus what Windows
operating system. So here we will be using the
codebook code block IDE met, and we will be seeing the
program and executing in both C19 weeks as
well as C plus plus. So we'll have the practical
session so that you will get DQ data structure. So far I stop on and let us see the basic thing
about the DQ. So what does this dequeue? It is also called DQ data. It is a linear list in which the insertion and deletion
takes place at both the ends. That is, dequeue means
in a couple of partners. And the q and the front-end, the insertion and deletion
takes place as well as the red and the insertion
and deletion takes place. So till now we have seen the cue in which
the insertion was thinking please
adult red end and the deletion in these
adult front-end. But in case of the dequeue, the difference is that
insertion and deletion, it will take place
at the front-end, as well as insertion
and deletion. It will also happen.
That will be total port operations
in your dq insertion. And we have already VM already seen in the
cues of what things are very few compared this BQ within humans we had seen in the
earlier open lab sessions. So first of all,
be in the queue. We have seen that we was
having consumption and the red and Andy was happening for
deletion at the Franklin. Additional operations which are there in case integral dQ
in the session which I'll explain you will be insertion
and the frontend as well as the bleaching and read and therefore
deletion and the red. So these additional
things are there. So we will be seeing these
four operations in case of the seesaw if
you just compare. And so the operation
code in social negative. Forming the board queue data structured as well as
DQ data structures or the implementation of the
function which will be writing will be the same in
both C language and C plus, plus and the deletion
at the front. And it will also be same, which we have further DQ. And for the queue
data structure, you will be aware of that. But the additional
things between the BC at the insertion
and deletion and better. And so we will see
what changes are required if we insert at
the front and watching this are required at
each of the things that required Wendy bleed adopt threat and this is possible and you will be using
here those circular area. We know the concept
of circular area. It is that whenever in case of the circular editor has seen it utilizes the
vacant positions, they're in your area. It will not be done. Even if you are rare
reaches max minus one. And if you wanted to
simply insert at the end, it will not stop
funding edit, edit. We said you are rare 0. Similarly, if you
want to delete, you want to delete and
you're at the front end, but you are of a front
reaches max minus one, so it will not stop deletion
events simply reset to 0. These are the things that is, these concepts we have already seen for the circular area, what happens, how it utilizes
the vacant position. This is the advantage or what? Just using the area. So that is the reason
we will be using the circular edit to efficiently use their
back and forth. Now, let us simply implemented this dq
Eddie using circularly. Let's move on to
this code block ID. So the PATRIC was in which
is required is that you need to download and
install the code block ID. It is easily available and let us simply
steps to install it. When you install it,
you can just write a program with me
bought implementing this DQ data structure and using this ocular Eddie and
just moving them. New project. That is, which I have
already created for C plus plus language. So this program is
for implementing the DQ using the circular
array in C plus plus. So I hope you know how
to create a new project, this one file click on
New and click on Project. Click on Console
application here. Then just click on Next, click on C plus plus, and just write the
name of the project. It should be the meaning Chuck, meaningful name for
a good practice. And just click on next
several 100 liters. So I will not create
again just to show you. That is the reason
I showed you now. This is the complete program
written in C plus plus. So first of all, what changes are required here? First of all, this is your
class by the name dq. That is, we are using
the circular area and urea having this class, I have defined all
these functions and the member variables. So if you'll see I've
declared member variables and I'm declaring them AND function. So I ended up public
access specifier. We are having an instructor, we are having a destructor, having these functions which are under the public
access specifiers. So we are having queue insert, so we are having total
pool of functions. What insertion and deletion, as we have seen in case of the cube in the
earlier session, we have only two operations, inserting and deleting
at the front end, but yet insertion and
Legion happens at front-end and better
woodland pseudocode era total for operations so that this queue insert
better than acumen. Certainly that is common
to both q and d q, this q insert Franklin, this is mu and this soap or the speaker at we
will be seeing in detail and delete front-end that is common to
queue and dequeue. And you need very
specific to this dequeue. Now, then we will
see how to display. Here we are not having
any peak function. And then the two functions
for skew MTN is tuple. Tuple, it's all these
other functions. Meters, meters, public. Then under the drive
it we are having the member variables as the
front-end red and the Q&A. This is a circular array, so we'll use this a sizes max. Here we will define the sizes. This is the Adi, and therefore, we have
to edit compile time. We have to give the size that we have given as sizes five. So I'll show you the example
which we will be using. We will have also made a
documentation for the example, the steps for insertion and
deletion and hold the ends. With dot diagram.
You will understand it more easily so you will make access to you so that you can report
it or to the voters. If I had made extra string, you call C Plus Plus language and literacy
so that you can copy paste and you can simply
execute at your end, you can check and you can simply understand the logic
which is there. Now. Moving to the main function, we have seen what functions
and videos are there. Then you just execute
your program. The control comes at the very first line that
is in this main function. And line-by-line,
these instructions are executed sequentially. Suppose this message I
have displayed to just know what is the purpose of a program implemented circular. Here. Just let me change to implement dq using
that circularity. This is bump this up at
our paragraph element, the DQ using circular array. And then you can
see since this is a class and to access
the member functions from outside the classes
from the mean function. I've created this static
object of this class. So the name of glasses D
Qaddafi had seen that, done. I have created this
object just static. Then I call this functions
for all this glass, I can call by this
static object, none of this valuable
in which we, as we have seen already via, via using vitamin because we are providing different,
different options. We don't want the, the
program distributed exited this menu to be exiting the user explicitly doing six. That is a reason, yeah, running our infinite loop
and just displaying all these options
to the user so that user can perform determine different operations still use, I don't want to mix it. And we are also provided
so that you can see here this display message and you're using the
switch case for this. We are providing good. If he doesn't want to insert
at the red end, user. Shouldn't doubt if
he wasn't want to insert at the prompt and you
just shoot and here too, if you don't want to
believe as a friend, can you judge user
to enter three? If the user wanted to delete it? You would go to the board and who displayed pipe
and to exit usually. And physics, these options we have the whiting accordingly. These are the switch cases
from Case one to six. And then finally
the default one. Just for one, we're asking the user entered
element to be inserted. So whenever you don't want user want to insert at the red end, then users should enter one. If he was on to
answer the front end, then you just hit Enter to all these options we are
providing that he was again accordingly enter these numbers which was collected in
this option option. We know it is the
datatype in detail because these are
the numbers one to the fourth is one and on that. Now, since then, here's whatever the user
entered element we're collecting in this video we'll be seeing is used
to ask the user to give the input from the console that we
will be collecting in this variable item C Alphas is used to display the
message in the C plus plus. So this item, if you'll see
I've declared here itself, this option in item is
of the datatype integer. Menu, see here that I'm
calling the queue insert red. And because your user enter one, that means the user wanted
to insert at the end and how we are falling via
colleague by the static object. And the minimum of the function
because we are accessing dysfunction of the class
outside the main function. So we are accessing by this
tactic object and endorse. Now at the dysfunction, you are pausing this item
it's user want to insert. Now what does this
definition now since you can see the name
and so dig into that. And this is common to
both this V-Q as well as the earlier Cube which we have seen in an earlier session, that how to insert
either the logic, if you see here,
will be the same. Let us move to this
definition of this function. So here, if you see here, if we insert at the
rear and how foods are, first of all, we know the concept of the
circularity pisiform. We have to check before inserting your protective
ambiguous full or not. If the queue is full, then
there is no point to insert. That wouldn't be a nice space in your area. You have passivity. Display them as HQ
or blue condition. You cannot insert photo
and you need to exit. What does it undetermined
want you fool? This is a condition for Q. It is the same, which is Aquadro on so the cube which we have
seen in an earlier session, beautiful enqueue friend, the
same for the circular area. That is, a plant is equal to 0 and my implicit equal
to max minus one. Both of these conditions
a satisfying, that is the reason you have
given n. In that case, it means your queue is full. You are useful to
this condition. If you have gone through
the earlier session, what implementing though, you have seen the audio
session of circular queue, which wasn't met in vivo
using this ocular eddie. Then you will understand this condition I have
shown with a diagram. You have children hold
the tube gets pulled in. This condition is
getting satisfying. This condition is
getting satisfied. This condition is
getting satisfied. Trend is equal, equal to their placement that
we have seen in the earlier session when we have implemented the
South, you know, Q, using the eddy that
was circulated, its debt is the same condition and then return one
and adds redundancy. And the QFD is also the
same condition parenthesis, if that is minus one,
then return one. If it is not minus one, that means returns you to
administer queue is not empty. These conditions we are using, so there it is.
Come beyond itself. In this insert they
read and they didn't. We have seen what is
the condition for q. We have seen that
condition is satisfied. It will return one and this message you will
displayed either you, if it is not satisfied, admins EOQ is having space and therefore
you can insert this. If condition will
not be satisfied, these instructions will not be executed and further
instructions will be executed. That is, you will be checking for different,
different condition. You will be taking that if
you are this minus one, that is if your queue, the queue is empty when
the DQ is MTV Notepad, this minus one in that case. So first of all, we know that whenever we
are inserting at the rare, and since we are
inserting at the end, we will the red end it says. So we're not concerned
about the front, but we are concerned
about different than the frame at the
initial statement that you vacuous empty. That case one will be minus one. So datetime only do you have foo simply diagram we have
two implemented by violence of drug becomes
0 otherwise whenever del Q is not empty space, then we have the norm deal with Dove brand when we started. We have to just change the red. There is a reason
just disability. And even dQ is empty then only we have to
change the front. Then we are inserting
either Aaron, I hope so you understood
that we're checking in. The queue is empty then just
to increment the front also. Now let us see how, what
changes are required. So since we are using, we are implementing using
the circular array, we know that rendered air
reaches to max minus one. And since we are
inserting the same thing, which we have seen for the queue or using the circular array, what a circular queue we have seen in the earlier session. We don't stop the insertion. We simply received a rare
to 0 that we have seen. This is not the condition. That is, if it is not
reaching max minus one, that means it is
different position. That gives us simple thing is
that we are incrementing by one and find a needle in
VR at that thread index, we are inserting the item
which users it entered. This is how the definition
of this skew insert better. I hope so you got, first of all, the another row. Let's come to the main
function and let's see if users simply enter two. That means you
don't want to enter an insert at the plant and not at the phase two
will be satisfied. Notice original function which is there in the queue, dequeue, which I will make you understand what changes are required, what modifications, what additional
functions you need to add when you
implement the DQ. Since here we are inserting
at the front end, that is a different and
different densities. What changes are required? Let us move to dysfunction. So first of all, we will ask the user to embedded element. And we will collect and we'll
pass that item element. That is our human,
this function. So let us move to the
queue, insert trunk, then you insert front-end. First of all, the same
thing for us to follow me. And since we are inserting, we need to check the skew. That is the same for
red and also insert. But another thing is that when this grant is equal
to minus one, that is, since we are inserting, you
have to check different, different condition
for Q will be object, not even taking the
time this minus one. That is, if your dq is empty, then you have to do EPA simply. Since you had inserting, then you have to make your
friend and read both of them as this thing
you have to add. And there are changes
which are here. What happens is that since you
are inserting at the front and this is new in case of the DQ in the QV
didn't have this, didn't have this function on if he wasn't starting
at the red end. But in this d cube
we're inserting at the front end
also it is allowed. So the thing that is
there that you have to add actually the
condition if your plant, since we are inserting
at the front-end, so we will touch front-end or maybe we won't touch reading except we're
touching that Aaron, on the event that Frankies minus one add the initial
statement that you want, the queue is empty then
only we are touching the red, yeah, making it as 0. Otherwise we will
not cover this. If you have to insert
at the front end, we will touch on me the fact, except in this condition. So here you can see if
the plant is equal, equal to 0, this is an
additional condition. Then since you want to insert. So what is the step-up in social whenever
we are inserting, we will be first of all, we have seen if we then he was inserting at the red
end because first of all, incrementing the red and then insulting so people's possible you're doing the implementation. Cost of all. The thing
is that there'll be inserting later
van be reached at particular index in case of inserting other
people's first of all, incrementing and then
we got inserting. That means there
are two ********, two parts which we have to do. First of all, we have to
increment the read Dan. Second part is we
have to insult. You have to always remember
that you will insert on the menu reach at
the particular, at the correct index,
then only you can insert. But in case of the
deletion, it is different. We have to collect the index of where it is debt that we
have to collect the item, we delete that item
and then we have to do the operation of
the implementation. There are two parts and
deletions, so forth. We will collect the items. Second participant, you will
perform increments, digits, but in case of insertion
plus million increment, when he was seeing in
session at random, we implemented a, then
B has simply inserted. I won't see you got the thing. The two parts that is in case of insertion get incrementing, then we are inserting when we
most inserting at the end. But in case of deletion,
we will delete. Then we will be
simply be, will be. We have implemented
the front in case when we are deleting
the plankton, not here since this
is in social and the plant then the things that is cowpox will be their perch upon where we will read that particular
index, correct index. Then we will insert, yet
checking if the front is equal, equal since we had
inserting a friend, we have to play with plant only. We will check if the front
is equal equal to 0. In that case, you have to make your claim to be
my max minus one. You have make your plan having the index of
the last element. So this stages is required it, and if your plant is not 0, it is having different
index and you need to insert since
you have to eat at dropper index so that in
that case you will decrement. So you can see this is a, this is a big change which is required when you are
inserting at the front end. You are decrementing,
you are not implementing everything
I've seen men, he goes intruding at
the PMOS first of all, no checking the pill conditions. But when he was doing he was
doing the incrementation. He was not doing the
decree mentation, but in case when you are
inserting at Franklin, you will, you are checking
different conditions. Finally, in this else's satisfied that is
your friend is not 0, you are doing certain
different index. In that case, you will
simply decrement your front. And then finally, you will be inserting these two parts are saying that as
you have doing, that is we have to focus on two particular index.
That is the first part. Second part is you need
to, and so that is same, but the thing is that we are in cases when you are
inserting at front end, you will be decrementing,
incrementing. And then finally,
this one index, you will be storing this item. This is a change, I will
tell you, understood. So first of all, these two
things is additional part you have to do is you have to check if a particular
equal equal to 0, then you have to make your
math tremendous max minus one. I hope so you understood
this concept. So this is the thing
that you need to check when you are
implementing the DQ. So you can just keep it to mind these foundations
which are there. And also we will see an
example in documentation, our deletion and insertion
both sides as possible. This video also clear the logic which we are
using here while executing. I will show that example and accordingly we will
see the operation. These are the things now
coming to the main function better than we are now seeing the deletion
and up front end. Once seeing the deletion
and the Franklin, we know that group or
bombed or deletion. We know how to
perform the deletion and the Franklin.
This is Coleman. It be checked as compared to the cube which we have seen
in an earlier session. Using the debt is we
have seen in case of circular queue using the EDI knowledge
earlier session, how to delete adopt front-end. First of all, let
us move on to this. When we deleted the front end, the case three
will be satisfied. You delete front-end, and
let us see the definition. First of all, it will
return the item which have deleted the same as compared to the circular queue which we have seen in our
earlier session. Delete that front-end
cluster followed by embed it men be deleting a project where
the queue is empty. If queue is empty, there is no point, there are no elements. There is no point of deleting elements since there
are no elements. What does the garden nation for? Umd? The condition is same. That is this ocular QD. I've seen scientists minus one, then it will return one
as it will return 0. Now, just seeing the
deletion and the front-end. So first of all, there
are two parts which are beautiful home,
they're deletion. The first part is that
you need to first of all, collected item which
needs to be deleted. And then second
part is you need to perform the operation
of implementation. Instance we are deleting
at the front end, which is common to
the circular queue which you have seen
an audio session. So here we will do
the implementation, will do the implementation of the front-end and then so forth. The post-partisan will
collect the items. Second part is we will be doing the incrementation
of the front-end. Since bus we had checked
queue is empty or not. Second thing we'll check. The next thing is that if
it's not empty valence, good, there are some elements. Then the thing
that we collect at the front-end development
indeed will collect in this item that is of
the datatype integer. This is a postpartum,
and then we delete. And the second thing, you
have to play with them. Now be able to
check vendettas on divine and human leptin E2. And then you need to delete
the Beckman element, which is their impact case. The same thing which
we have seen in those circular queue
and audio session. Then we'll make the
front and bred to minus one when only one element
is left and the deck, and he meant only
you need to delete. In that case, you will make the front-end rare to minus
one that we have seen. The same condition than the front reaches
to max minus one. And then since we are using the circular ready in that case, We've been made the front as 0. That thing which we have seen in an earlier session as described
is not max minus one. The simple thing that we
will increment the front. And then finally the
item which we have collected earlier
that we will return. So this is what whenever we are deleting
at the front-end. So this is common for the, for the audio circular
queue which we have seen using it
in audio session. Just let's move on. Let's see.
12. Deque using Circular Array QueueSession6Lecture2: Let's see one
additional function now which we are left with, that is deletion and the better. And this is new in
case of the DQ. So far this, the case
forward will be satisfying. This one will be satisfying. And you are calling the dequeued separate function
DDGT underscore. Here. If you see here this q, dq or delete underscore
wherein you, first of all, since
we are deleting, you need to always check
for the QFD or not. If it is an empty
node point to delete, then if it is not
empty, well and good, you will collect the element
at the front end in this. This. If you see here, this is rare actually confront. You will be deleting
this element which is present at the red
and you'll be collecting. And since we are deleting the read end, that
is the reason. We'll simply collect
the item that is present at the
index editor index, and then we'll perform
different operations. So the different operation does, is that when scientists
equal equal to R1, that means only one
I haven't slept in your D2L and that
we need to delete. You will make this one. That is, you have
seen this is common. This is, this part
is there since you're using the circular area, then another thing that changes, which is required as
editing and theme is that you are rare reaches to 0. Since we are deleting the
red answered the formula. Taking different conditions for rare infrared is equal to 0, then you have to, if
you didn't have to make your red S max minus one, then we want to solve
in 30 at the frontend, we have seen that foster, one of the first
part is you need to do the operation of
degree mentation. You have to change it
into thin conditions of the front end. And then if it is, you'll be billed checking
that if rent is equal equal to 0 and then we're just
incrementing the front. And then he was inserting
the element in case of, that was in case of
insertion at the front. And now we're deletion
at the red end, we need to collect the item
which we need to delete. Then we need to check if
the red is equal to 0, then we have to
make it as Mexico, these things to be
a project post. And then we have to also check that if marriage
is equal to 0, then read will be max minus one. The else condition that
is normal condition. If it is there that is
having different index, then you need to
simply the material. So we have converted
in treatment, but we have remainder. So these things
are new in case of this dq of NBER delete
when we are diluting. Just keep into mind all these conditions
which are required, these additional, additional
condition which is required. And then finally,
we need to return the item which we have
already collected here. I hope so. You understood the dysfunction, their dispute delete
at the red end. Now just we will
also see the example and you'll understand the
mood board that I had made a document for different
operations and I will have already
shared with you, so you can just refer to it. It will make your
understanding very easy. Now, you have seen
all these options, put options not at liberty. The display function
for that end-user should end up on a
refusal on to the spleen. And it will call the
display from static object. Now on display, the
elements same if you have gone through my audio session of
circular queue using EDI. But didn't we have seen
how to display that? First of all, we have to check whether the
queue is empty. There are no elements, that means you don't
need, you cannot sleep. There are no elements. Simply you need to exit. If the queue is not empty, the condition is not satisfied. Further instructions
will be executed. Us simply how to display we have seen stop all what we are doing is that we are
collecting them. First of all in case
from Trenton bread, how we have seen how to display the elements and
not earlier session. Flow time is lesser
or equal to red. Bottle demo having
different index. In that case, you
have some elements, data elements present
between front-end read. The therefore, you have to
simply display like this. Since you are I is equal to Frank and trying to
less or equal to there, then you have to simply
checked and you don't reach. Keep on displaying
the elements and you need to keep,
keep on incrementing. I hope so you have gone through all your session of
implementing this. Are you using the array so
that you will be aware, aware of what, what this
condition is there. So we're checking if the
plant is less than that it is friend is having less index whereas having
greater than index. So the elements are there
within front-end red. And this is how we need to split if the front
is greater than rather desert is
having less index and Frank is having high index, in that case foster hall, since we are displaying
from the starting to make post IS 0 and then we will simply
till I reach is rare. We will keep on
displaying each elements. Once we display all
elemental be reached there, then we will reset the trunk. Then I will be planned, and then till we reach
max minus one will display all the elements in the array and we will
be implementing. This is how you display the
elements in case of the dq, which is same as
if you see FCFs. If you have seen in
the earlier session of circular queue using EDI, Let's move on to
the main function. If you want to exhibit
the use of an anchor six, then finally you will be exited. And the quality
of these options. Use it on Exhibit
a invalid option. I'm done with
company dome program of implementing the detail
using the circular area. I hope you understood the additional functions
which are required. Now let's first talk
all known before executing the program for let me first of all
build this file. If you see here, if I believe that this is a blogger
and you see the buildup, you need to simply walk
to the view and you need to check on the laws
that you will get the below. There are no changes since
I've already compiled it. So if you compile the file, you can see no
errors, 0 warnings. Now before executing
the program, let us move to the
document and understand it better so that you will
understand it properly. Now, we have seen that changes. So these are the insertion and
the addition operation and DQ this I had made available
to you this document. You can simply view this
document or these other in social deletion and
woodlands Vandana in red and then the initially manures. Just let me modify this
is their DQ actually. Yes. Dq is empty. So we know
when the queue is empty, the front-end read
voltage minus one. We know that both of
them will be minus one. Manual queue is empty, so that is also same
for the dequeue, also Friend and Redis minus one. Now you are, you want
to insert at the end. When you need to insert
at the 1021 by one, we will be inserting
possible insert ten. I've also written
the steps here. Menu insert ten. Initially you dequeue is empty. In that case, breadboard will
be implemented by months. We'll look of them
will become 0. And since we are inserting, the right-hand side
is equal to 0. At 0, we will be
inserting the element. You can see here the
steps I have written initial event queue is
empty and you insert in the front and red is equal
to 0, then is inserted. And then second time
when you insert 20. In that case, since you
are inserting adrenaline, you need to play
with the red on me. Therefore, you will simply
increment your red. So that becomes one. Yet in this manner
and physically to 0. In that case of guarantees and warranties and started
actually in this case, if you see here, 20
will be inserted. That it will be inserted, it will be inserted at
the red is equal to one. It will be like this. Frank will be 0 radically
provided and 20 is inserted. You can see twenties
and started at Drell is equal to
one and display. So first implementation is done of the red and
then 20s uncertainty. This is common for
queue and dequeue we have seen when we
inserted the reading. Now again we are inserting, but here you can see we are inserting at
the plant and not. Now let us see what
changes are required. So first of all, when we are
inserting at the front-end, now, we are inserting 25. Here you can see what
is first of all, the different is 0
and that is one. So fast. We have checked actually here when the friend
is equal to 0, then function min-max minus one. We have seen a nano itself. If you see here, it'd
be insert though at the time ten here this is the, this is the Q program
queue insert front. And we have seen, we have
checked if it is minus one, both of them will become 0. It means that if the parameter 0 and we will make the
frankness max minus one. This is the thing.
That is if you are inserting the plant and your
friend is how much it is 0. That means since you are
inserting at the front-end, front is 0, you should make, you're trying to
maximize minus one. So Frank will become
maximize this one. That is, it should
have their next one. The last element that
is, it should have the indexes photo of
time to become bored. You can see here, friend
becomes for this step. This step. Let me
write in this manner. So here, this becomes
this and net yard. Then you would then read
becomes two, becomes four. And your friend defined. You can see here
Twenty-five is inserted at this the ED trunk and that is
simply at the board index. So I'm also you
understood this operation is different in case of the DQ. Now, when you are inserting that codified at the front
and you can see there are different things with blank because now you have to
insert the 35, the front end. Let us see what is funny. Current is equal to four. Now you'll cry intensity by
Stokoe and max minus one. So we have this maximum. So Francis water
actually practice for post-op Honda
prime is non-zero, so their friend is dead for this else condition
is satisfied. That is this one. Since the index, trend, trend is equal to four. In ad, displays, insert 35 or friend and
your friend is four. Therefore, this is not
satisfying this condition. Therefore the else
will be satisfied. That is, your friend will be became a painting
and then you will be inserting the element will be the Klimt painting and you
will insert the elements. So therefore, you can
see here that trend is for actually not
run becomes three. And at this study this
35 will be inserted. So it will be in this manner. Like this. First degree mentation of crime takes place and then
you are inserting 35 at your front-end. So I hope so You got this. You can see how we
are comparing with Dido program itself when you are deleting
from the read end. So this is also different thing which we have seen in the D2. Since we have, we have. What does this deletion
and the red, reddened. So first of all,
what is your red? Red is equal to one. Therefore, first of all, whenever you are deleting, the first part is you have
to simply collect the item which you need to delete
that is equal to one. So that means this
is, this is your end. You have two simpler
that is fun. This domain D you need
to simply delete. So therefore you will collect
this 20 newer item media. And then what you will do since red is one that you see here, this condition of delete that
decided this is our delete. This, so this condition will be satisfied because you read
is non-zero, it is one. Therefore, this
will be satisfied. You will decrement.
If you see here row, you'll see here,
you'll read becomes 0. It was fun, but so first of all, you will collect the
item which is dead. This render you will collect the item you want
to delete that. So therefore you will collect this element at the index
this weekend available item. And then you will decrement
the read from one to 0. This was one, Then you
have seen it becomes 0. And the practice as it is, that is rent is how
much it is three, so this will be as it is. You can see here. The next operation menu
delete from the content. Now we know that deletion confront and we are
already aware of, we have seen in the queue how the deletion at the
front-end takes place. First of all alone, we need to simply
what is your plan? Index fund indexes. That means at the tree
this 35 is present, that we need to delete. This 35 will be deleted, will collect in the item. And then these three men we are deleting from the front-end. In that case, we will
do the implementation. Then he was deleting from the red and we was doing
the documentation. This deletion from
the front end. So therefore,
instrumentation takes place. So this 35 is deleted and
your friend becomes four. If you see here, you'll see here if your
friend becomes four. So first of all, this, this is deleted 35 and
your friend becomes full. It is incremented
and Redis as it is, that is 0. I hope so. You are getting all
these things now when we are diluting
at the reference, now, when we delete. In that case it is different. Yes. What is the operation
cost of all what is rare? Rare is equal to 0 and
we wanted to delete it. In that case, what we
will be doing post-op all post-doc on the red is 0. That means at the 0 index the
standard will be deleted. And if it is 0, then we
know we need to maximize. The rash should go VO2, max ratio become max minus one. Richard had been indexed, explored, the stand
will be deleted. And since red is equal to 0, since we are
deleting at the end, we have to check
different conditions. So what is red?
Red is equal to 0 when you are deleting
that quoted. In this condition, we have
seen men ever be deleting. And when it is 0, that is 0 revenue become max
minus one. So that is 0. At this point. We will delete this
ten which is present, and a 0 will delete this ten, which is present
at the 0th index. And then since the red is
0, you can see it as 0. Then read becomes max minus one that is available
to have the index of the last element so that
it becomes equal to four. So you can see here,
there before it becomes forward and
trying this acid. Now the last operation
which is just shown here, whenever you need to insert
either reading certain 90, that is quite as EB
have seen already how to insert so far that
what is your end? Red end is equal to four
minute to insert 90. So that in case of the sort, since this is a circular area, reaches max minus one, red is equal to four. That is having their
next softness element. And we need to insert the data. And so we have seen when
that air reaches here. So this operation we have seen, first of all, in
social and the data, and this is in social advantage. That AD is equal to max. We have seen bread is
equal to max minus one becomes zeros. Here. The red is equal to four. Therefore, foster hall
low then will become 0, that is 0, and then
90 will be inserted. You can see here
nineties and sorted. So the air will become
090 will be inserted. So this is all about
the insertion and deletion and hold the
instrument in and rerun, which is which occurs
only in case of the DQ. These two insertion and
deletion occurs at both ends, at the red end and therefore
data for our patients. So now let us execute the program and understand
it more better. Same thing we will be executing. If you see here though, I
have made those sizes fine. I picked up the same example. You can see this is
the size of the areas the document understand more
better what things are done. So now let us just
execute how to execute. And since we have already
compiled build and run. When you build and run actually, now let us see BD2K. I'll show you in this
manner on me. So far. So far, initially your queue was empty when certain and
20 at the red end. Let us end up either
inserting and the red and maybe in center
option ten, we'll do ten. Again, we'll insert
an interruption, then we'll enter 20. And for displaying
five minutes to enter, we can see here element
is ten and even just 20. Now the next top,
next operation here, what we're doing, we
have inserted this, so Dan and 20 or
the next operation, what we are doing,
you are inserting at the 25 at the front end. So therefore, what
do insert though? The plant and we
will click on Enter. Then we've been insert
25. Yeah, inserting 25. So just and you'll see
here entitlements. So we'd entered Monday,
we'll enter 25. And then we simply
disbelieving enterprise. So you can see here 102025. You can see here. That
means that 25102025, it is displaying all
of these elements. Now notice, so do this
operation that is in violence or Cat5
at the front end. For that, to insert
though at the front end, we need to click Enter
again and we enter two. Then it asks me what
element I have inserted, d Phi, d Phi. And when I click on Display, you can see a 1020 thirty five, twenty five, twenty
five, twenty five. What we have done here. Now when we delete
from the front end. So let us click on the option for deleting
from the front-end. For that we have to enter
three. We will display pipe. So you can see here 102025. This is the Endo 35 is deleted. So you can see here
we have been bowed, deletion and the crime tender, as you can see here,
1025 will be displayed. So first of all, let us see. Then whenever we won't
be having sorted, then we delete from the
private and we have seen in social and or deleting from
the front end for that, we have to enter the on
bleeding from the trunk. And you can see here, if you see here, we are
deleting thrombo that enforced. So now let us see
this operation. Addition from the right end, the delete from the red
and we need to enter. And then if you
just click on five, you will see 102525
will be the split. That as you can see,
102525 will be displayed. Now, the next operation is
deleting from the front end. When we are deleting
at the front end. And then we just
click on display. Now 1025, it is left
will be the split. Now we have to delete
either Erin for that. You'll see here I'll enter
code whenever we need to. Then it will, it will
delete the item. And then if you'd split, you'd see on neither element
at this 25 to be as an IP, you poke around in 1990
or the red end book, insert the 90th a dead end. He will simply Kaylee Kanban. And if you just enter the
element to insert 1990 and I, if I click on Display, then you can see here
we are having 1925. So this is how there are
different operations were insertion and deletion
and board hands their discontent and be done with this
complete execution of the program which is
written in C plus plus language for Windows operating
system for implementing this dq using these
circular adding. Now the same thing I've seen, logic will be there. If you write the same program in C language on the data
will reveal. Thanks. Syntax changes. Other, that is, if you write the program same
program logical the same, so you don't need to worry. You have the same. Simply
changed the syntax. I have already created the
project in the C language. And the same logic I have
written for you, you, and you need to
create a new project since I've already created, in case of my gate, in my case, I've already created how to create the project new
project policy language. Click on File and New
and then project, and simply click on Console
Application. Click on Next. Now you will click Enter C, since you are writing the
program in C language, and then click Next, give
the short meaningful name for good practice.
Then click on Next. This is how you'll create a new project since I'm
already created and just show you the program
which I had written. Only the syntax changes there. The logic is same as we have seen in the
C plus plus also. Now this is the project. You can see main.cc. So here we know that all the
functions which are there, all I have made as global. So therefore you can
see first of all, you'll include these header
files and here it is. Let me do the changes. Yeah. You're going to
include these two header file I, O dot edge. Since you will call printf, scanf and C language, it is printf scanf
you need to call to display the message
and to accept input from the user on
the console scanner to use input from the
user on the pencil. And printf is used for
display the message. So do you have to include
these header files? Then since you are using
the circular area, you know addi is in
which compile them, you have to decline in the size. Therefore, we have, we are
defining the size pipe. So I'll pick up the same
example which I have shown you now for the C Plus Plus language
also this area had made. So all these things you
can see these are globals, these variables,
that is the Adi. And then front-end
read this max I've used you all are in
essence EOQ is empty, that you're initializing
it to minus one. Then you can see here these four functions
which are required, that is all our meters global. You can see here this q insert and the red end, this is dead. This is made as global, then few insert
at the front end, this is viewed as global. Then q delete at the
front can curate. And so if you know
what, I didn't dequeue all these four operations are, they're inserting, deleting
at front end and variance. So these four things are
required and Ganymede as global, since we can directly access it from the main function in
here there is no class. And that is more static
object consultants. And this is a C language, but the logic is same, which we have
already seen so far. The logic understanding
you can just report the earlier which are for the
C Plus Plus language parent I've made you. And then we'll compute logic
of these four functions. Now the display
just syntax changes are there for the spleen, which dysfunction
there are QM, PQ full. Now when you execute
your program, the control comes in
this main function, line-by-line instructions
will be executed faster. This display messages there. So that you will
understand usable understand what is the
purpose of our program that is programmed to
implement the queue using circular area in
this infinite loop. But in this infinite loop, you are giving options. We have already seen
earlier also in C plus plus language in 1.1 for inserting at VO2 or inserting
front entry for diluting and deleting at the front end or for deleting Piper
display six for exit. These options which
are the switch case, the user enter one, that means you don't
want to insert it. And the same thing, since
in to insert either read an app called dysfunction medically, you inserted it. And what is the definition
of this function? It is same as we have seen for C plus plus language, also, the same logic I have
copy-paste actually, just how I'd made
this function global. So there is no name of the class since there is no
class and cplusplus directly dysfunction
is defining your biggest seem that if your queue is full, then you need to exit. You cannot insert
if the front is minus one, then you
have to do like, parent will be 0, reaches max minus one, there will become 0. So all these things are advisor will be
getting implemented. Finally, you will
insert the item. So I'm just quickly rushing
in this explaining you in C language because the logic or handmade you line-by-line. I have explained you in detail when we will have seen men. V&v have seen the same program in C plus plus language
for logic understanding, you can report the C
plus plus program, which I have explained
the recording session that is in my earlier part
of this session itself. But in explained
the complete logic in XYZ policy language, you can just go to this program. I had also made this
code available. Similarly the user to user one to Insert and then this
case two will be executed. And finally, this that is your paycheck,
you is full or not. That is different than
DQ in the C Plus Plus language to describe
what made you understand on an earlier project
does current session, it is seemed the logic is saying you are inserting
at the front end. So what you are doing, you need to check if the queue is full. You cannot insert the, otherwise
the plant is minus one. Since we're inserting
at front-end, both of them will become 0. And if, then, if it
is, the current is 0, in that case, L
Frank will be max minus one is that you have
to decrement the plant. The same logic which I've
explained, currency plus, plus language also, just before the earlier part,
biologic understanding. Recall my first part
of this session, this current session itself, the video clip and syntax. You can put obscene language. You can come to this program and see how have gold the function, how the function is made global, all these things and
then we are inserting. Now the same thing. If you don't want to
delete at the content. Therefore, user will enter three per deletion from
Trenton will become, and what is their
definition? The same thing. Deletion from Frank. Q. You need to check actually, that is.
13. Priority Queue Linked List QueueSession7Lecture1: Welcome to the new
session offering in the program and in
particular thing or implementing the priority queue using the linked list in C
language and C plus plus. We will be doing the
practical session in which we will be
creating the new project in the code block
IDE for admin routes operating system for board
C language and C plus plus, we will be seeing the program for both languages
and executing it. So first of all,
let us understand. Let's understand what is this priority queue
by the name itself. You can understand
that is it is, it is based on editing,
but what does it mean? It means the element which is having the head is priority, it will be inserted and so on. If you are having total
number of elements, so the element which is having the highest priority
will be inserted. Very first element which will be having the priority
but it is hired, but it is lesser
than the high end of one deposit element
that you have inserted. That will be the second
element that will be inserted. Again. The third element
which will be there, it will be having the
parity but listening earlier one and so on. So that means the
last element will be having noticed rarity. So you can understand,
depending upon the priority, these elements will decide, should be placed in
the queue and that is an reason this name is
the priority queue. What about if there are multiple elements
without having the same? In that case, it will be the people that is
first-in, first-out. So depending the
agreement outta, there are three elements having the same priorities with the one which you are
angry and queen, that is inserting force
will be inserted post. And the element which you are inserting off the debt
will be inserted. So it will be it will
be the first the first one which which is processed. We'll be insert very first. He understood that
when we talk about the rarity of the elements. Yet if you see, first of all, this insertion,
as I told you it, it is competitively or heavy operation because
in which you have to post all search element
which is having the highest priority
and you have to ensure that it should be
placed very poached. Your queue is empty initially, and one-by-one you are
inserting elements. You are asking the user to foster fall enter the
value of the element, and you are asking the user to enter the priority
of that element. Now, you initially when
your queue is empty. So first of all, you will
that element with, with the, with the priority with user have given next time when you, another element is inserted
with another priority. And you will check
that priority with the very first element which
you have inserted because we have to make sure
that you meant having the highest priority should be inserted very first and so on. So you can understand there are a number of elements then
you need to do this. Hydrogen, you have made this, you have to maintain
the sequence. Then the element which is
having the highest priority will be inserted post and so on. The sequence will go on. This is how there is a
reason this task is heavy. What about the deletion operation
in this priority queue? It is a z because postpone, as we know that the
highest element and our priority
with the highest, the element with the
highest priorities inserted ready false. So therefore, when you
delete that only element which is inserted posts
will be deleted post. That is a reason
you don't need to do heavy task in this easily. You can perform the deletion because the sequence
are arranged. Insignia because these elements are arranged in sequence order. The limit which is inserted
for us when we deleted posts and so on In all these things takes place
in this priority queue. So we know that this insertion
is called as in green, and this denotes addition
is called as dQ, DQ in case of d q. Now let us see that things
on this priority queue. So first off, one by
this priority queue is implemented using
the linked list and by not using the area. So first of all, we
will be seeing that we'll be seeing the program of this priority queue
and that we'll be using the linked list and
we will not use x, y. And what is the
reason behind me are not using the area
and we are going, we are preferring linked
list because if you can understand if we are
arranging the elements, we have these elements and this shifting of
all the elements. The element is the very
last element we have to please very first you can see how much shifting
is required. So we know it is very
heavy task if we use the EDI because we need
to shift the elements. In that case, it is non-preferred using the array
in case of the linked list, insertion and deletion
in-between is very easy and it's
very efficient. That is the reason
we are going to implement a priority queue
using that linked list. So this is a reason.
So all these things that have
made an old dumped, you can just refine it. Now, first of all,
as I told you, the element which is having the highest priority will
be inserted very post. What they want is
highest priority means. So first off on, this
priority will be, will be in terms of impedance, the private thing above one. Priority number one is
considered the highest priority. Priority number two is
considered a priority lesser than the polarity
one, you can understand. So number one is still
having the highest strategy. Number two will be having the priority lesser
than the polarity. One. Number three will be
having the lesser priority compared to the earlier
priority, that is to N1. So there are six elements. So you can understand
that their strategy starts from impurities
from one to six. So the polarity one will be
the highest priority and priorities six will be the US. You can understand how we are answering the highest priority. Now, let us see the
example of this. This priority queue is used CPU scheduling
algorithm in which uses this priority queue because in which the CPU processors, the jobs which is having the
highest but either default, so it processes
those jobs first, which is having the
highest priority. So that is, that is a thing. Disparity cue comes in, shoots CPU scheduling algorithm. Now first-off on the two
operations which are important in this priority
queue is in social, which is called as enqueue. The deletion, which
is called as GQ VC. How will perform this insertion deletion
using the linked list. Now this is just a diagram
to show you how it looks. When all the
elements, one-by-one, you ask the user to enter and you ask the user to
enter the parity. You have asked the user
to enter a one-by-one. You asking for three elements. You have asked for the priority. So this is a sequence
they will be arranged. Can see here, this is the
UBI using the linked list. First of all, you
can see it this is called as a node in
the linked list. You can see here this notice
having the address 100. Suppose the second node is
having the address 153rd. Notice having
interesting 100 me know, in case of the linked list, we are first of
all having though, parts as the information. The first part will
be having that. The next part will be
having the address of the next node. If you can see here, in case of this firstNode, we are having three parts. The three parts in this
case of the priority queue. First of all, the element
value, we are constraint, we are taking all the datatype
integer, so support that. As you can see I've
mentioned here, this is an N Suppose user game and the priority
of that element. Two parts will be about the data force will be
the value of the element, and the next will be the
priority of that element. Therefore, you can see, you can see here to
forest pattern data three parts. First, second bond. These are all having
their data by so-called one is having clarity and that is having the
value of the element. And the third part is having the address on the next element. It is, it is, it is since it is linking to
the next element. So you can see our next
element is having address 150, so it is storing 150 as address. You can see the second node. It is having first of all, clarity than the aluminum value. And the third part is having the address of the
next node that is 300. And you can see the last
node which is present here. It is having the link as none. Since this video, using
a singly linked list, it isn't linked list. We had just the last, you know, that the last node is
having the link is null in case of the singly-linked list. And this is how you can see the priority L. Or
if you see the priority, the first priority
element is stored post the second priority
store next to that. And the part, but it is stored mouse you can
see the sequences, how the man is having
is considered as the highest priority to consider the variety
which is lesser than one. Cities having considered as
the authority dissident. Sudden one. This one is the
high-spirited is, there is an easy and it isn't
so deliberately forest. You can see it is present in 3D. Now, let us implement this priority queue using the linked list in C
language and C plus plus. You need to, the prerequisite
for this is that you need to download and
install the code, not IV. And it is very easy to
download and install. It's very simple steps. I just recommend you
all to install it. On your answer that
you can simply write a program with
me and you can just execute it so you will have a proper understanding
and didn't unless you don't write
the program yourself, you made all these code available to you so you
can simply are reported, you simply copy paste
and you can drag that your answer that you
will understand. You can. Both on different operations of this priority queue have
already opened or not. I'd just moving through that. I have already created a project
or C plus plus language. So we know the
process of creating a new project in block ID,
just quickly devising, we need to click on File, New Project, and then just
click on console application. So here just click on Next. Since we are writing the
program in C plus plus, just click on the C plus,
plus is highlighted, click on Next and just give
the chart meaningful name. Then click on Next. I will not clicked because I've
already created a project and then written the
program does make you understand what is the
concept behind it. So since it's a C
plus plus programming only have to give all
these header files. Be able to give this namespace. Now in C plus plus, we know that the class, you have to first of
all define the class. So this is the
glass with the name PriorityQueue
underscore linked list. And I have the public
access specifier and private and public
access specifier. I've used this constructor. The constructor that
is a destructive. Then that is the functions
which I made as public. The queue insert to
insert that image. You delete, to delete
the element of Anu of the frame display to
display all the elements of the PriorityQueue is QM to
protect whether they're ready, queue is empty or not. And under the private
access specifier, we have used this struct node. Vfb I did a pointer
to the struct node. So what does struct
node will have? The node, this one,
I'm gonna say. This struct node will have
the priority postdoc, all of the datatype integer. Then it will have data of the datatype integer and infant has struck
node pointer link. It will have links
to the next node. If you see here, first of all, this
one, you can see, if you can see the discourse, know that we have taken us
on deleted abstract node, it is having the postpartum
as the priority. That is our datatype integer. Second part as the element
value of the datatype integer. And the third link that is
a pointer to the next node. That is practical. This is what you have
to take this struck. We are creating the pointer
to this structure S prime, so we will have
only one pointer, will be pointing that is here. This will be just if you
consider this diagram here, the false node pointer. There is only 1 and that is a front point and that is pointing to the
first mode. It will. We have to make sure
on this plan points to always consider one front point, but it is pointing
to this first node. I have not written here, but just to consider, we are having one pointer
that is pointing to this force, the linked list. So we have to make
sure that there aren't always points to the first
node of the LinkedList. Now, if you want this class, now this functions
which are there, that is that you insert,
delete being displayed, all these functions notifying outside the class
you can see here. And that is a reason I'm Nick, I mentioning the
name of the class, scope resolution and
this function name and the definition of it. Here. Again, you can see
the rescue and so that is the
name of the class, scope resolution
and the function. And then we are having the definition he
got in this function again, you can see here which function? Yeah, thank you. Delete, which is defined outside
the class, therefore, the name on the glass
full resolution and this definition
of this function. Now peak. Again, it is defined outside
the class that we have to mention the name of the
class scope resolution. The definition. Then display your defining
outside the class. So name of the class
scope resolution. You can see here this main
function which is there, which is outside the class. So first of all,
we will be calling all these functions of insertion deletion of that
is from the mean function. So we have to create
a static object. We are creating a static object. This is an e-mail, the
class you can see here, we are creating a
static objects so that by the static object
I can call different, different function of
insertion deletion and all which are
related to the class. If you see in this main
function, the body pose. If you see here, when you
are just display message, this will give the
purpose of our program. It says programmed to implement the priority queue using linked
list in C plus plus nine, which these are the videos which are declared,
which we will see. We will make use of it
optional item and clarity. This is the name of the
class and lock that recheck. Do you know why they're
creating objects? Since we'll be calling the
functions of the class. So you need, require a
static object of the class. So that is the reason we're
creating the object heel. Down here. If you see I'm using a vitamin and in which
we're having this, which case you can
see here, it will be, have seen this multiple times in our earlier session on Somalia
using an infinite loop. First of all be born
that usage should have different options and
don't use one to exit. Allow users to perform different different
operations like insertion, deletion, peak, and displace
within won't be exempted. You don't want to exit
from this infinite loop. That option me, I have
also provided as exit. User will enter five and
then it will come out of this loop that is outside
this infinite loop. Now, display message
that is abuse I wanted to perform in certain user
has gone into one user, deletion username there too. What peak it will use E1, E2, and E3 for display use of an NDA fall for exhibiting
seven enter pipe. And all these options and
connecting in this video, we'll option this option which is dead is of the datatype in. You can see here. This is 123. So
depending upon that, this case will be executed,
support insertion. This case one will be executed, then HE or deletion case
two will be executed. Focus or peak value
three will be executed for display
port will be executed, and then 45 exit
will be executed. Now, just moving to this case, one supposed to fall, um, what data users should
enter onto the console? Since we are talking here
about a priority queue, I didn't want the user to enter the element value and we are taking this element value of
the datatype integer value, then ask the user to enter. And also we're asking the
user to enter the priority, he was like an end
and any priority on that element military
for 56 anything. And accordingly, we have to just ensure that we will insert the element in the order in which the high-speed editor
element will be pleased. Very posts and so on. We have to make sure
that it's added. It's audio programming. It's not according
which should take care up all these things that, depending upon the priority
range on these elements. And therefore, you can see here on display message will be
there on the console, enter the element to be
inserted in the queue. You will understand and
user will enter the value we will collect in this item
that is on datatype integer. Again, we are asking user to enter the priority
of that element. So use the milk
collected value in the priority in this insert, which we are calling
by static object. But you insert yet
passing this item, that is the element value and this priority
of that element. So let us see here
in this insertion, what is the definition
of dysfunction.
14. Priority Queue using Linked List QueueSession7Lecture2: Now let us see here
in this insertion, what is the definition
of this function? First of all, if you see
here this priority queue, which is queue insert, this item is dead
and this strategy. Now, first of all, we have to insert the element. This is a C plus,
plus negative B. So that is the reason we are
using new Soviet impasto, whole new node since we
have to insert a new node. Therefore, we will create
by this norm pointers. What does this more point out? This is the one which
we have already. We are already having a
struck by the name node. And all these things. If the V consists of all these things that board
when we called the queue, insert, creating one new node. That is a reason why this
node pointer newNode, we are giving that name and only occluding the new
node by giving you, then, then that is a
structure name is known. We are creating the new node. And here we'll see where
we are making use of ETL. So first of all, since we
need to insert the new node, that is the reason
we are creating this new node in this manner. So first of all, we are checking if the new
node is equal to null. In that case, we will give
them the message that's not available in the memory
hadn't even exit, exit. But if this is not null, that is, that is
this is not null. That means we have
space and therefore, even simply fill this new node. So you can understand this
new node which will be dead. That only node we
need to insert in our linked list depending
upon the priority so far. So that is the reason
you're feeding the new norm when
it is successful. That means is if
it's not, is fine. In that case, we are feeling don't know the values
of node is having the cost of all the priority and the element
and then the link. So first of all, in
stock tibia having this notice having priority data that is element
value and then link, let us address to the next
node that but if you see here q insert function
here, this data, new node data that will be filling with this element value, that is item which
user has entered, which is the first
argument in this function, the item clarity on, so that is a new node. And this second
data is priority, so that we are filling with
the item is user heaven. So you have this, fill all
these data in your new node. That is our data. And therefore, now you have to, you have, you have good check actually not what is remaining. You have filled this priority, I fill this element,
this link is remaining. Now we have to make short here actually post often
that can be different, different Phoenicians when you
are inserting any element, the condition can be
that your queue is empty and the node with
you will be inserted. That will be our course node in the queue. In that empty Q. If Q is initially empty and
the node which you are, you want to insert the node in. The condition can be
then that you had having only one node in
your credit in your queue. And then you want to
insert the new node. So this if condition
is for that, that is, it is four. If the queue is empty and
the node you want to insert, that is only the one node that you want to insert in your cube. It can be though
another condition, only one element is
present in your queue. And that is the condition. And you need to insert one
more element in the queue, which is having
only one element. These two conditions on
quadratic condition, you can see here, is q empty? What is the condition for SQM D? Let us check heal. Faster fall. You'll see here is
pure MD in which since we are having
only 1 in that case, you will be given
your practice none. We know that we are
having only one pointer and that of course, motive that is only null. That means your queue is empty. That will ensure that
your queue is empty. That is the reason
this is one condition. If this condition is there. If you want to heavy the
only one node which is present and that one node you
have to take deep breath. No. Because if you add having
only one hold in your cube, new node which you
want to insult. You said have given the
priority on deck node, right? So you have to make sure that the priority which is having, you have to ensure
that the highest priority element will be placed very posts already done. Q, if it is having one node, if it is having the priority S2, the new in order
that you want to insert the user enter the priority S1. So
we are considering. The highest debt and element on limit is having Ts one that is a
high-speed activity should be. Please post that. Notice that. But she was I wanted to
insert and if it is having the priority is one and only one node
which is president or Q. It is having the polarity x2. This new node we
have to put before. Don't only node
which is present in the queue that is
having the priority to. The new node is having
clarity months. So it should be placed
first and then, then, then before that of the element which is already present in the
curators having me, but it goes, we have to
maintain the sequence in. This condition is for that
if your queue is empty, there is nothing is
present in your queue. So first of all,
what you are doing, you are filling your new
node with all these data, that is data and
what you will do, you will do new node link. Emmanuel queue is empty. We know that client
is null in that case. That is a reason
this new node link will be quite different. There is nothing
present in your queue. You have already, you want
to insert a new node. You have already
build these data and you have two
remaining to fill with. The link to be that if there is no nodes in the queue and it is only the new node
which you need to insert. Links should be not. The reason I'm giving you a node link is equal to
front because we know that the queue is empty to simply give you a
link equal to null. That new node, which
is the substance we have to maintain the front
pointing to the first node. So that is only the node width
is inserted in the queue. Default branch should
also point to let you know that is the reason
this is a second night. Current is equal to I won't.
So you understood this. This is manual queue
is empty also, the same line of instruction
will be executed. What does this item priority? So we add collecting
this IMT priority, the priority of the element, which user wanted to insert. That one. We have competing if that one. Yeah, Taking that if
it is lesser gravity, suppose the US is
lesser than that. So this will be only,
they can placement. You are having only
one node in the queue. So this was when
your queue is empty, the sign is lineup
instruction will be executed when you are having
only one node in the queue, and then you need to
insert the next node. So this, this condition, you have to check for that,
the disorder condition. So in that case, this
item underscore, but I edited the
priority of death don't load if it is lesser. So we know that the
priority if it is one that leaf node which is
having the polarity too. So the priority one will be considered as highest strategy. We have to ensure
that it will be inserted very first year. There is a reason we
are checking that if the priority of that element
which we need to insert, if it is lesser than that of the one norm which is having a foster parent is
pointing to that node. And we have that as
a reason we have to check the priority of the current element which
uses is in so doing, we have to check the polarity
of that brand strategy. So if the identity that she was I wanted
to insert if it is having less separated as
compared to the priority, then we have two element which was the one who insert
should be false before. And therefore the same code that is therefore the new node which you have
already filled here. Since it is having the
priority images Lisa, that is, it is having the polarity lesser in the sense the number which
are all vector quantities. One, already well-known,
which is having its spread. It is true Aneesh and will be satisfying
in that case, right? Therefore, in that case, that means you should
install this node, which is having a strategy one before the node which is
already present in the cube. So to insert before, you have already figured
out new node and therefore you will be
writing like this, that new node link. It has done since you have been sold a known before
the front deco, new node link will
be equal to front. And now plant will be pointing to null because you
will change the front because you have
pleases new node before the front and therefore the front
is shipped to them. We will also point
to the new node. This is how these instructions
will be executed. And what does this in this
venue or queue is not empty. And when that IS null, instead us to three nodes
present, then this S. There'll be satisfied
in that case. In that case, first
of all, first of all, when this condition
will be satisfied here, then the element
which you want to insert it is having the priority lesser than
that of the practice. In that case, this
instruction will be executed. That means you have to insert that new element
before the track. And therefore this is two
lanes up instruction that food before this plant actually
you should use the new node. Therefore, the new node, meaning not run,
could be modified. It will be coming
back to the new node, certainly pointing
to the new node. Then these instructions
will be executed. So either the queue is empty or either this condition
is satisfied, then these two lines
up instructor will be executed as the front. The item priorities breath up, and then let go of the
punk attitude admins item, which user wanted to insert it if it is having the highest, higher priority than
that no-load fund. That case you are item new
element should be inserted. It should not be inserted
before the front. We have to simply compare this polarity of
that element with other elements also which is, which is present in the queue, we have to check and we have to simply ensure that we installed that new element
before the element, which is having the higher
priority as compared to that of the mean which
we want to insert. Because in that case we'll maintain the sequence so that this isn't what we are doing. We are collecting this
front in this PTI. What is this PDF? This
PDF is first of all, in this node pointer. We will collect this to here. And now what we will
do as we have already, as we have already compared new element clarity with
bet on deep learning. Now next time we
will be comparing the new element with
all other elements, which is that in the queue exit the front because we
have checked that, that is a reason here we take a y loop and you can see here I loop we are taking PTR link should not be equal to null. And the PDL, what is,
what does it mean? We are checking like this, FQDN should not
be equal to null. Because first of all, this just this instruction
is then because you have to, first of all,
ensure that the new elements which you
want to insert, you will have to
foster volume check. Didn't you get this element, new element lesser
than the elements, which is that in the queue. If you saw, if you don't get
the element which is having, if you don't get the
elements switches having the highest fidelity as compared to that of the element which you want to
insert in that time, you won't usually be able to check with all the elements which is present in the queue. And therefore this
condition is used that is, checking if the PTR
linked should not be equal to none because costa qualities be
data will be checking. You ever want to recheck
the UN even upfront one? That is a reason
this while loop, it will start from
if you see here, this is using N condition. Yvonne, his condition
should be satisfied. So this false condition, I'll talk about it now. This second condition,
what it is, the PDF link that you see here, we are not doing PTR priority. They're not taking that PDF
writer of the item priority. We are taking ppm link priority. We are taking the link
because we have here earlier, we have already
checked this PTR. I had a D, there is a
plan for parity with that new elements by Saturday in that is a reason
this might loop. It will check the second
element, the next element. What does this text element? We will get a PDF. Notice it isn't, and we
will take that reality. Check. The element. You are limited with this greater or equal priority of the current of
the next element. In that case, we have
to simply move on. In that case, this condition and as balance this
condition, that is, since we even be
reframe PTR, link it, bring it via, mentioning it as post condition that links
are not equal to null. Since we have to compare all
the elements of the node. That is the reason we are
checked using this condition. So this two condition
should be satisfied, then only this instruction
will be executed. So that means if the item
priority new element is greater than or
equal to not of B. Got it off. The next element of the queue. In that case, we have to
iterate to the next element. Again, let's check the condition because what we are
supposed to do finally, this new element
we need to insult. We have to just ensure the proper place of
the new element. You have to make sure
that this new element should be inserted. And the please
before the element, which is search should be at inserted before
the element which is having the highest priority, which is having the higher
priority as compared to add a new element. That new element is only having the highest standard in
then we have to keep on checking the data elements whether other element is having the priority higher or if it is having lesser
than if it is heavy. And decide new element
is having the higher as compared to the elements which are already
present in the tube. And we have a coupon
Mooney will be in short it for all the
elements of the queue. Because we know that the new
element clarity to be the less than that of any notes
without present in the queue. Then we will simply insert the new element
before that node. Because we have
to make sure that we insert element in
the sequence wise, depending upon the
priority should be lesser. The value should be less
than, should be lesser. Because we have two
item priority mode. If it is, you have
to make sure it is inserted at the
proper, please. The element which is having the editing greater than that. There is a reason if we
don't find them mean, always find this
parity to be greater than we have to
keep on moving to the next element will be find the ultimate priority greater than that of being human
elements priority. Then we have to stop. And then we have
to finally insert. So once we find though any
element in the node which is having the highest ITS as
compared to new elements. Then we have to insert this
new element before that, which is having the
highest validity and how to insertions, we'll be inserting this new
element before that animal. Therefore, that element link actually which should,
which is there. In that case, that
elementally will be stuck on since we have to insert this new element
before that element. And therefore in that case, first of all, in that case, there is a reason
what we are doing. First of all, my PTR link. Because if you just check this
diagram or this new node, and this new node
that you don't have given the event venue is 20
and the priorities three, if you just one-by-one, we have checked this polarity. So if you see here, the if condition will
not be satisfied. Because the same condition as we can see at this polarity, it is the faster it
is greater than them. First node, which is having
the priority is one. Also it is greater
than the second node. It is having capacity S2. Now your PDR is here. First of all, this location
you can see this is the PDF without Rodinia and this is pointing
to the second node. Now, what we are
doing at this point, we are checking the PTR. You can see here
by this PTR link, this PDL link priority. So when we are at this, we're pointing to
the second node, but still we are
writing PTR link. This PTR link is the third
node and its priorities for we are checking whether this priority is necessarily
quality to the new nodes. Priorities are new
node priority, if you see it is three. So if you can see
here cost of one, this condition is not satisfied. Because you can see
here this first. So you can see
here first of all, this priority, first of all, of the node is should
be lesser than or equal to that of
the item parity. So this newNode costs. So in this case, we can insert this new node. When we get inserted this
new node only when we find the priority of this new node
to be sudden the elements. Then, then non-meat
weekend and so that node. So when we are at
this PTR pointer, then we're checking that in
this new node which is dead, if it is having the, if it is having this, it will stop moving
to the next Telemann, then only this new node
is having the priority. So we are taking that
PTR link priority. You can see epithelium
priorities, food. If it is lesser than
or equal to new node. So first of all, whether four is less than or equal to three. Now this condition
is not satisfied. That means this will
not be executed. That means you found the item priority value to be lesser than the
PAPR link rarity. That means this new
node polarities having the lesser priority as compared
to that of the PTR link, that is this node priority. Therefore, you have
to stop moving to the next node because you found the place where
you need to install. And finally, you
will have to simply, since you are at PDR, but you are checking
the polarity of the next node in the new node. Since you've found that
new node is having the priority lesser
than that next node, then you can simply,
that means this. You add at this point. Now you have to insert this
node activity after this PPF. In that case, what will be the modification you
have to break this link. This would, after this PTR, this more new node should come. And after this new node, this node should become
because you have to insert this new node between this
PDL and between this node. Therefore, what will be there? So what does a PPR link? Whenever the PDL linked
is there should be the new node link because you're inserting the new
node in-between this. So therefore this museum
maintain this PTR link. So you just save this PTM link. New node links should
be equal to PTR link. So therefore this new node
link to require PTR link. And finally, PTR links should
be then equal to new node. So PDR linked to be
equal to new nodes. So I hope you understood, and that is a reason
this logic is used. That is, we are, when we add, add this PTR still we're not checking the
priority of that node, but we are taking the
parity of the next node. Since we have to insert this
new node after this PDF, that is the reason
we don't want to lose the reference of this PTR. They could add this PDL itself. We're taking up the next node. And accordingly, we found them, you'll note priority lesser than we found the police
to be inserted. Finally, this notion
of being sorted between these two nodes, and this is done instruction
which should be executed. I hope so you understood
this while loop when we should be should execute this instruction that is
BPR is equal to vt element. We should keep on traversing
to the next node. It will be done find actually this new node
priority lesser than or lesser than that
of the priority of the note which is
debt in the queue. That time we have
to keep wondering once we find the
priority of the new node lesser than that of the
this node priority. Then we are, We found the place and we have
to insert that node. So this is the code, the logic for inserting
the new node. Now, let's see if
the user wanted to simply perform the
deletion operation, who is able to enter
two and this case two will be executed. And then we are calling
the delete function here.
15. Priority Queue using Linked List QueueSession7Lecture3: The delete function
definition will go here. It is very straightforward. Still haunted by inserting, we have ensured that
at the very highest and the aluminum having the
highest fidelity that is a priority one will be inserted false element having declared it to be inserted after
that, and so on. So it's very easy to
delete the elements. So we have to delete the element where the plant is pointing. Already that we get
the sequence in proper order and the product that it is pointing, you
have to delete that. So before deleting, we have to check if the queue is empty. For checking the QFD, we have seen a tremendous null. That means the queue is empty. It will return true
and we should exit. If the queue is not empty, then only we can delete
that are limits and we can do to delete the node. So suppose we have to delete this grant is pointing
to this first node. First of all, always a prime will be pointing
to the first node. In that case, if
you have to delete this node, foster hall, we have to return the element which is
present in this node. And we have to simply take
the backup of this node because we have to also look at the memory which
is required by this node, will collect the
item from this node. And then we will, first of all, we will take one more pointer which is
pointing to this node. We will collect the item
present from this node. We will move on to
the next node because this node is deleted then the French pointer
to the next node. Therefore, we should will point to the next node
and then we will be bringing the space
which is required by this ignored.
So how to do that? So there is a reason you
are taking one more time. Why? Because we will
the temperature be pointing to the plant and
they were this instruction. Then we will collect the
data from the ten we collect in this item that
is of the data advantage. Then we will make the front to point to the next node
because after deleting, this, tranquil will be
pointing to this node. Parenthesis equal
to frightening. After we modify this current, then we will deallocate the
memory versus rid of head up. Temp is pointing,
temp is pointing. Immediate look at memory. Then we will get the
EMF is equal to null. And then in-between you
have collected here. This is simple operation
on delete, no vendor, user enter p is three
will be executed. N means it filled return value. We're calling by static
object the peak function. And what does the speed? Biggest and biliary
check and vacuous empty, you cannot perform
the underturn. The present value of
the queue is not empty. That means element is present, that mean return the data. This is how we perform
different, different operations. Not if user to enter
a enter for you, we'll display that
humans not hard to display the element
that is also simple, we are calling by the static object, you
underscored display. And what is the
definition offered? Definition is that first of
all, if the queue is empty, there is no point to display
elements Up to exit if Q is not empty valence
elements present. And then what women do, since we are having the
front pointer pointing to this first node will take
this plan pointer to another. We'll take one more pointer
which is pointing to the first node where
the front is pointing. Me even keep on displaying
all the elements, will keep on moving
that pointer to next, next node and simply display
that element of that node. One by one will display
all the elements, elements of that node. So therefore we are
taking one node temp. The temp is pointing to
trend and we are checking. We don't reach to the end. We will simply we simply
put in the date type and we also simply print the priority according to the n. We don't
reach till the end. We will keep on connecting
each and every element on me. This is how we are displaying, so I hope so you want
the complete different, different operations in
social division feed display N5 user and then
Despite will be exiting. And if you don't enter anything, then invalid option will
come. That is a reform. This is the complete program which is written in C
plus plus language. Now let's focus on the operations are
suppose I write here, compile the current file. You can see here
this comes here. It is no arrows. So you're if you will,
then be then run, if you do, it will
execute the code here. So it will ask
different options. Suppose we want to insert into insert 1 million enter
the limit is ten, will enter the
polarity as again, MY want to insert will enter and 1 million Newman test 60. He learned the
priority is three. Then if we're going to display, will do for display. You can see here what
it displayed first, cluster quality,
you can see here. I'll even the 60 priority three. So we have classified inserted two elements,
that is 1060. The false we inserted ten
with the priority is full. Then we inserted the elements 60 with the priority is three. You're going to understand
this priority three is lesser than the priority for, so this should be
inserted posts. So if you see the sequence
for its element is 16 is coming with clarity three, and then element
n is coming with clarity for you
can see then it is simply arranging the elements depending upon the priority. The priority three
is having high, it means it is having highest fidelity as compared
to the priority for Lewis number is considered as the highest strategy
that popularity three is lower than four, therefore, it is having
the higher priority as compared to the clarity pole. This is how this works. Actually, you can
see if you want to delete and we will simply
click for display. Therefore, you can see here, first of all, it gives
the item 16 is deleted. And then when you
display will get only then to be the split if you again enter two
and if you enter, it says queue is empty already, then ten is also
delete it as nothing President still we are displaying it says
he was a leader, does not come to display. These all things are done in
Q1 to enter for the peak on, so you can enter the same,
the different options. Now, first of all, we will love, we have seen this program in C
plus plus language. Now let's see the same program
written in C language. So I'll quickly,
because I've made you understand the complete logic
in C plus plus language. So same logic, same code we will be using in
C language also, but there will be a
slight syntax difference. If you want to understand
code in depth, you can get for the first
part of the session dinner, which have explained for C
Plus Plus Project language, but an unexplained the logic, the code in detail. If you want to. End for the syntax, you can report this main.cc, this program redundancy
language for the syntax, you can report this main.cc
proposed explanation. You can report the first part of this session,
but in explaining, explaining the logic in the sleepless physicals logic
is seen for C plus plus and C only the syntax difference
is that the fossil follow the same funding all those functions
which I told you. First of all, we will have in C language you have to
create a project as file, new, and then project. And on console
application click on Next and then you have to
highlight the C language. And then next, like
this language, next, you have to buy additional
chart meaningful name. And then this is how you
can create a new project. Once you create a new project. And for the C language, this is a code when
you are having the struct node as global, which is having the polarity
data and node pointer link. The same thing as we had
seen in C plus plus, but this is meters
global in C plus plus, we had a class where
we had a constructor, destructor and different things. So these functions are global
in case of the C language. And we are having
only main function. From main function
we will directly, depending upon the
switch case environment we have written the switch case, we would call
directly the function by calling the insert function. You know that you
have already seen in detail in the postpartum
causing less plus project. The logic, what's used? Suppose user one to
insert user within the one that will be
collected in this option. And we're asking user to
enter the lumen to be in. So it didn't yet
also asking user to enter the priority
that elements. So we'll select the
priority and in this video, we will pass these two values
in this insert function, the same thing, just slice
and thanks differences there. So if you see here the main
function which is dead, the insert function was presented
as having two argument. Identify clarity,
what we are doing. First of all, you
want to insert, therefore, we aren't
using struct, node pointer and videos. What does this stamp? And
we are allocating memory. We're calling malloc
function and I pass the white pointer to struct
node star and find a DB Guan, understand, we got
the memory allocated. The name temp is
pointing to that memory. Then we check if this
temp is equal to null, that means there is no space
available in the memory. And then if this is not
satisfied well and good, that means it has space and
therefore you can simply fill your yard node with this data, the use of it to use in some item and human value
that you have to fill in this data of the node
and this priority of that. So you have to fill, you have to fill the priority
in this newNode though. You have to fill this node which you have allocated memory and your pre-fill all the data's in this manner which
you have seen here. The same logic if
else condition, if condition and
your queue is empty or if you're a drone priority, DTM, if it is, let us say
they end up trying priority, the node first node
which is dead. In that case, these two
instruction will be executed. The quarter on vendor for identity of the
United new element. If it is having the lesser
priority than the company. And we have to insert
in this manner, that is the attempt Vitruvius, that new node three updated if misbehave already
written priority. So it's linked should return
on debt financing is what? The queue is empty or
if this condition is satisfied in this grand null. In that case, usually
the front is null. The constructor, we have
a sine n. First of all, the stem, which we have created a look at them
how many physical data? That will be the n. So this will execute. What else if the queue
is not empty and display indigenous North satisfying that means which condition
is satisfied? The priority of the
new element if it is greater or equal
to that of the plan. That case this else
will be executed. That case we have to find the location of the element whenever you need to protect mu. And demanded is the new
elements one by one, we will be moving
to the next element and we will see
whether the new and even that it is a vessel if it is less than N2
debt of that element, next element of the queue, and that gives me an insert that new animal in that please. That is a reason
assigning plan to PDF. Then we are checking
this two condition is used and by using n, you have seen that in earlier
part of the session also. So first of all, this
PTR linked rarity. So when we are at PTR, we will be checking the
priority of the next node, not the priority
of this current. And even maybe
there is pointing, it'll check the polarity
of the next node, that company clarity
of that new element. And accordingly, we will decide whether we
need to insert. So once we find a new
node priority lesser than that of that
next node priority, then we will stop moving
to the next node. That is, in that is, this while loop will
not be executed and silently install it though. You know, to this new node, we are at this BTL. We need to insert this new node. So this PTR link we will
be saving to new norm PTR. You can see a PTA link we're
saving to the stem link. And this link will
be equal to ten. It will be equal to ten. The same thing which we have
seen in C plus plus also, I hope you understood the insertion function using Enter to then deletion
will be performed. And therefore, this
nation function, we have actually
deletion function. We are checking MTO
queue is empty, that is null point,
delete. We will exit. The queue is not empty, that
means our elements we can delete to the same
thing we've been sent me take one
more pointer temp. We even assign
this time to time. We will collect the data
from the stamp in this item, we'll move on to the next node. And then we will see though it was pointing to
the first node. And we'll do them
who seem logic, which is if the user
enter like this. If the user enter three, that means you don't want to
poke on the peak operation. In that case, the user will do, user will enter them. Going to the main
function user will, in this case, three
will be executed. P function is called. In this function,
what we are doing, we are first checking whether
the queue is empty, empty, we cannot perform peak because
it will return the fund. There is no element in
the queue is empty. If the queue is not empty,
valence with disability not be executed and it does
return the current data. Now, the next thing which
we have to check is that the user entered for display
function will be on display. What logic is used? First of all, when
the queue is empty, there is no element present the participant, it will exit. If the queue is empty, then president exited
the queue is not empty, then we have put a split displaying
what we will be doing. This is just slightly
incident is displayed function will be taking whether the queue is
empty, queue is empty. That means there is no
element present in the queue. There is no point to display. Simply exit. The queue is not empty then punishment
normally satisfied. We lead sign this front to M. M is also pointing to though. This VIA checking if it
is not equal to null, we will keep on displaying
the data and the priority, and we'll move to the next node. It will be at each
node we will keep on display the data in the
priority accordingly. This is a y loop on that. And then finally the logical be completed so you can understand how you're
displaying the elements. Now just coming to them. Finally, if the
user enter 12345, then five will be executed and then we
will exit from exit. If he was on one to enter the exit you
associate enter five, then five will be executed. If the user known antennae
option then DePaul invalid opportunity,
execute result. Let's run the program. Compile the current file here. Therefore, your cost of all, let us build a board. Confined the current file. You can see annoy areas
and then build and run. We will then rather
than in social MAN enter the limit n. Suppose
we uninjured Ford priority. Again, one insert. We are both enter
the limit as 15, putting the polarity S2, we are done entering
as for display. So you can see here, since
we have inserted post ten, but with clarity for next, we have inserted 50. But with the clarity
to this priority to having is considered
as element having the highest priority as compared to the element
which is having the priority for this 50
should be inserted posts. So you can see here when
we display an even 50s, the spleen and then
element tennis displayed. So you can see how it takes place when we need to
delete will enter two. You can see posts
will be deleted. And then if you want to perform
P, we learned the three, it will return this ten
because 50 is deleted, you are left only
with one element. There is ten and that
only it is the peak value is drink if you wanted
to exit and up this mu, this is how you
will exit faster. Now I am done. The complete veteran, we have seen how to implement this PriorityQueue
using the linked list. First of all, we have seen
what is priority queue. Depending upon the
priority the elements are arranged and even having the
highest priority, that is, that is the ones considered
as high strategy is considered as
the lower priority as compared to the priority. But therefore we will
be inserting elements. And even science
or depending upon the polarity credit
IS priority will be, will be inserted
posts and so on. The number of elements
or having seen priority, then it will follow
the people who rules. The first element which is inserted will be
pleased post and so on. So this is what about the priority queue and we have seen in social
is heavy because we have preserved the proper please where we
have two inside that even because we have to maintain the priority of the element
in the sequence auto. Insertion is heavy, in
addition is a z because since we are inserting in the sequence or the deposition is in Z. Now also we have checked the director why we are implementing priority
queue using LinkedLists. By not using Erin edit will be heavy
because we have to shift all the elements one by one and LinkedList and social niches and dopamine are implementing
using linked list. An example we have seen that we have in different operations. We have seen this diagram. You can see here one priority, one element is inserted
pause and variety is inserted after that and Friday for is
inserted after that. You want to insert, we're
caught logic instead. This is how we have seen the company session
on implementing the priority queue using the linked list in
C language and C plus plus also I made the
code available to all. You can simply copy, paste the code at
your end and you can simply execute programs. I'm done for now, friends,
thanks for your time. Thanks a lot.