Transcripts
1. Overview DataStructures&Algorithms Series1: Hi, welcome to the first
session of the course, stack. Use and linked list
practical programs, DSA, that is data structures
and algorithms series one, using both C language
as well as C plus plus. Here, the very first
session of the course, I will be listing
what all topics we will be covering in
the entire course. You'll be understanding the
data structures that are stacked use and linked
list concert twice. And we will be doing
lots of hands-on in order to understand
these data structures. We will be also doing
the hands-on in order to understand the applications
of this data structure. I have covered all
this lecture sessions on whiteboard as well as on both systems so
that you will understand these data structures
more thoroughly. So let's start and let's see what topics we will be covering in depth
in this complete. Moving on to the new slide, that is Session one,
different sessions. And under decisions
there will be lectures. The very first session
which is in production. Because structures
here we will be seeing what are the
cost structures, what are data
structures are there, and what is the importance? What are its advantages
and disadvantages to details about data structures we'll be seeing in this session, one session to this stack theoretical and practical
sessions on my board. That is, we will understand that the test structured
that is stacked. You'll understand this concept will see the program
and they too have explained on the
whiteboard solidarity video lectures
under this section, lecture one and lecture two, I will be covering
stack introduction. So there are small video clips. I have a word in part one and part two of the same
stack and production. Didn't. We will be seeing
the detail about the stack. What is stack, how it is used? Much mode in these lectures
we will understand. Then in lecture three, we will be seeing the program that is stack using arrays with
programming in C, the program how to implement
the stack using it. Eddie. So there are different ways in which we
can implement the stack. So you can see the program in this lecture three will
understand in more detail. Then lecture four is to implement the stack
using linked list in C, the program for the
same and see how to implement stacks
using linked list. Then the new session, that is session that
we'll be covering the application that is stack
application on by both. So I have a word here, the application of the stack
I've explained on the board. So there are different
lectures under this session. So an ecto 123 is one theme application that is in order to
reverse the string, but using the stack. Then same session, the different application
of the stack. This lecture, we will see the expression is having them at balanced
parenthesis or not. So here I'll explain you. What is this balanced
parenthesis? So detail about it. I will explain you in
the dedicated lectures, just understand this is one important application
on the stack. We achieve more efficiently
using the stack. So different video clips
or their part one, part two to achieve
the same application. And lecture six is
another application, important application of
the stack that is infix to postfix conversion left
to right associativity. Here in this lecture we will
understand what is in fixed, what is post fixed
by this conversion required and how to
achieve this conversion. So partial fallen short to
see this main purpose of this application is to evaluate your mathematical
expression very quickly. This conversion is required and there are different
ways to achieve it. Left to right associativity in fixed or fourth fixed gun motion doing left or right
associativity and just have an infix
to postfix conversion using doing right to
left, left to right. And this is right-to-left,
different minutes. So just knock one. Now just understand
this is in order to evaluate your mathematical
expression really quickly. This application is very
much required in detail, we'll see in the
dedicated lectures. Then another lecture for the same session for the
application on the stack is in fixed to force the
program for concept. That is how to achieve it, how to achieve and motion
of infix to postfix. That results in this lecture, we will see the
concept Lecture 67. And the program is, I have dedicated lecture 89. It is the same program. In order to achieve that is, the program will be the same. Asked that isn't fixed to
cause fixed fun version. You'll see the program in
this lecture 89 and nature and spot evaluation of the course, fixed
postfix evaluation. So that means here you
can see that finally, we will get the
postfix conversion. So we have to evaluate
that expression, which will be in the
postfix form that we will see the concept in
lecture ten and we will see the
program in Lecture 11. In, in order to evaluate the course with all the
details about this, maybe you've seen the
dedicated lectures. These are the important
application on the stack. Then. Dialect known. Then the another lecture dwell that is for the same session for the stack application is in fixed or prefix conversion
rule with examples. So earlier sessions lectures were called infix to postfix. This lecture is in
fixed to prefix. This same posts on this
fun version again to say it is to evaluate the mathematical
expression quickly. This you can also
convert infix to prefix. So you can do in
fixture costs fixed, you can do in Pix2Pix
also be the same. Now in order to evaluate
the information quickly are required for
the details about it. You'll see in electric drill and we will do the recording, will write the program, feed the same in
fixture group prefects in lecture talking. This is all about the
application of stack, the new session in this stack theoretical
and practical session on left pump
that is on the system. So we will be writing
the program and executing on the
operating system, on the system using
C and C plus plus, we will see different programs
of the stack and we'll execute lecture one is to write the program and execute to implement stack using
an array in C language. And C plus plus will implement the stack using erin
write a program for it and will execute it if you see language
and C plus plus. Lecture two is to implement the stack to write a program
and implements stack using linked list using
in C language and cplusplus lecture and saw all the concepts I have explained you in the earlier
session on the whiteboard. Now in this session, this will be execution, writing program execution
on the system that you can see how you can do different
operations of the stack. Now, lecture three is
to write a program for an executing for application on the stack
call balanced parenthesis. So defensive and I have explained you on the whiteboard
in the earlier session. So here we will write the
program and execute on this. And I will check how the expression is having
balanced parenthesis or not. Then in the same session,
different lectures. Here is their program and execute in order to
convert infix to postfix and to evaluate postfix and C language
and C plus plus, there are different parts of it. We have already covered the concept and details on the whiteboard in
our earlier session. This session, we'll be
covering on the system. We will be doing hands-on on the system and write
the program and executing on this system to achieve this application on this tank
that is in fixed reports, fixed and motion debt
evaluation of postfix, different parts, part one
and part two are the same. Well, same application. Now, Lecture six is write a program in
execution or in fixed. Now this was one in
fixed reports fixed, this is in fixture
prefix and evaluation of prefix in CNC plasma, again, we'll write a program execute on the system in order
to convert in Pix2Pix are fixed and
in order to evaluate the prefix using
these languages, C and C plus plus, then. Now the new session will be for the different data
structure that is Q. So yes, I should have studied all about in detail
about the stack. Now this session we'll
start for the cubes. Use theoretical and
practical session. On the left-hand side,
you'll see the programming execute on the system
in different lectures, different programs are there
or the view that is writing the program executing our queue using an array in
C and C plus plus, we will implement queue using Eddy in C and C plus
plus then lecture do is for writing the program and
executing implement code 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
some cooler linked list. So we'll see what a
circular linked list, how to implement queue using
the circular linked list. So these all are different, different programs for the use 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 the system, you'll understand
in more detail. Then lecture board is to write
a program and execute code implementing
circular queue using an array in C and C plus
for the different parts, part one and part two. In order to implement circular
queue using an array. Then Lecture six is for writing program and
executing the DQ. You'll see also what
is DQ and we'll implement it a culinary. See what a circular array then what is v2 and how to implement the queue using circular area in C language and cplusplus. Then in lecture seven, there will be proved writing
program and execute, detailed execution of
presidency or his gratitude dq, then you'll implement
PriorityQueue using the linked list in C and C plus plus programming
execute on the system. In this manner we
will be completing. And then we will be coming to the different data structure
that is linked list, linked list theoretical
and practical session on whiteboards or this mean I
understand on the whiteboard. In lecture one,
we will be seeing what is their different,
really see detail. What is linked list? There are different
types of linked lists. The linked list, singly linked list
is one other type of the linked list
means see what is the singly-linked list
and we will see in detail about it in this
introduction in lecture one. Lecture two, and
lecture three is your main function I
have covered so far. We know that in C
language and C plus, plus the entry of
an execution of a program starts from
the main function. When you execute your program, the control comes to the main
function and nine by nine, the instructions
will be executed. So the details about it, I have explained you in this lecture for the
singly-linked list program. What is, what we'll have
in the main function? Part one, part of the program. I explained you then
in lecture four actually we will see there are different operations for
the singly-linked list. So one of the operation
is to add a node at the beginning of the
singly-linked list that we'll see in lecture four. Then another operation of singly-linked list
is to add a node, a new node after a
given node that we will see how to add a new
node after a given node. Then this lecture Six Sigma
program for adding reform, that is to add new node before
given node, how to add it? That operation we will be
seeing in this lecture, six different parts product one, lecture sentence covered the
part two of that program. Then lecture eight is what adding the given
node at position, position will be also given. Node will be also given
which node you have to add in this and how
to achieve in C, the program, this
intellectual aid. Then we intellectual nine, we will be seeing the program
for creating this thing, how to create a
singly-linked list that programming is missing
in the lecture nine. Then we will be seeing how to display the singly linked list, how to display the nodes
of this in getting his foster father
Indian production really understand
singly linked list. And what are notes that are notes in the same in
English that all details. I have got one
Indonesian lecture, how to display all the nodes
of the signal in English. How good is failing
singly-linked list deviancy if you see the program and
we've seen this lecture ten. In lecture 11, we will see how to count the nodes
on the linked list. How many nodes sound
energy will see that programming will be seen for the same mean
increase in lecture 11. Then Lecture 12,
or displaying and counting nodes on the
list will display the program how to display the nodes something is and
how to count how many home, how to count the nodes on the
list, singly-linked list. Admin seen the lecture
12, then, then different. Then we've seen the
different lecture is there to cover a singly linked list program for deleting nodes. How to delete a given node on the singly-linked list
that is in this lecture, then different lecture part for the program for
searching your procedure. Such the node on the
singly-linked list every receive the program for it in this lecture, then
different lecture, we will see that a singly-linked list
program for reversing how to reverse a
singly-linked list that we've seen in this lecture. Then we will becoming
to the WE linkages. So in the earlier
lectures we were seeing about signaling
is now different. Another type of linked list, WE LinkedList detail about
it in this lecture, 16. In this lecture, that is a
willingness in production. And another lecture will
be writing the program. So there are
different operations on the doubly-linked list then that we will be doing now in different,
different lectures. This lecture is for doubly-linked list
programming order to earned abroad venue
or list is empty. Then when you have to add up new node in the
doubly linked list, this is a program are the same. Then another program is to doubly-linked list program to add the node at the beginning. So when you have to know, you have to add a node at the beginning of the
doubly-linked list. How to achieve that program
is there in this mixture. Then another lecture is the doubly-linked list program to add at the end
on the envelope. So whenever we have to
add a new node on the, on the doubly-linked list. Then how to add at the end? How to add that program will
be there in this lecture. Then doubly-linked list
programmed to add. The mode on the listed is
whenever you have to add a new node after a given node
in the doubly-linked lists. How to achieve that program
will be there here in this lecture that I'm
explaining your new data. And then doubly-linked list program to add the
corn or whenever you have to add a
new node before a given node on the
doubly-linked list, the program will be there. Then we will be seeing how to create a
doubly-linked list and this mixture in this
different lecture that you'll see the
program for it. Then another lecture is
to delete the nodes. Whenever we have to
delete any node on the doubly-linked list how to achieve and see the program
here in this lecture. Another lecture is to reverse
the doubly-linked list. How to reverse a meaningless, definitely seen this lecture. Then, doubly-linked
list program to how to display the DAP notes on
the doubly-linked list that we'll see the
program in this lecture 25 in the next session
of this course. Maybe it'd be also seen the
application of use that all the queues are
used efficiently. So I'll be covering the lecture, one of the lecture for
these applications. Then in next session
may be seeing also the application
of linked list, where all the linked list
can be used efficiently. So also I have covered the practical session for
these applications of the cube In my last
link that is thought to add mode on the application
of linked list. I have already important
application is to manipulate the polynomial
expression using a linked list. So I'm explain the
theoretical part on the white board as well
as I have also followed the practical section
on the old block ID on you will come across
this important application. And also I will be sharing
with you the code for all of these programs for
these data structures and application so that
you can access it, you can refer it, and you can also implement
it by the frame. In this manner, we will
not complete course. We will be deeply studying understanding these
data structures. I'm surprised as well as
practically for this session I'm done and be ready for the Hertz sessions
and lectures. We'll be going sequentially. So thank you friends. Thanks a lot. Let's meet in the next
session of this course. Thank you.
2. Stack using Array C & C++ Session1: Hi and welcome to
the new session that is stacked in data structures
and unguarded them. So here in this session, given rewriting the program to implement a stack
using EDI and C, as well as C plus plus
on the code block IDE, as well as we will
execute that ball. We know that this
code block IDE, it is freely available. You need to download it and
you can simply install it. It is very easy to install. And this is how you're
going to get the IDE. And then you can pay
the program and execute a proper hands-on and C
as well as C plus plus. Now just before moving
to the blog ID, Let's just quickly see
the overview of this tax. So already we have seen
in the session but a detail that is about
the stack or the stack, how important it is. We have seen the
real-world example. We have also seen the basic
operations for the stack. We know that push and pop and always spoke bombed
from the top. You know, that stack
follows last-in, first-out, That is the last
element which is pushed in the very
first element. We know that we are having the top as a reference
for, for forming Bush. And here we will be
seeing all these. We will see, we will be writing the program to perform
all these bush Bob. As well as we will be
seeing the completion. This peak operation,
we know that we will be returning the very
last element of the stack. It will not pop anything. Then we will also display
the elements of the stack. This is how we implement
various functions. All the functions
we've got acquired, implement the stack using the editor and we'll
be running it. And C plus, plus as well as c. We know that when
the stack is empty, in that case, the top minus one. So what will be the
top in that case? And the stack is empty, it will be minus one. We know that in case on
the edit first of all, the indexing starts from
012 till n minus one. Therefore, when the stack
is empty, the heavy, we will be initializing this variable that has
stopped to be minus one. And suppose now we have
to push one element, that is the number.
We have to push. In this fact, we know
that first of all, all the elements will be on
the same day that they've suppose we have the element of the integers for all
the limits will be on datatype integer
supposedly had proposed actor than
all the elements of the stack will be on the data
type character and so on. Depending upon the requirement, you have to push number
five in my stack. In Italy, my stack
is empty and I put up is equilibrium minus one. So in order to perform
the push operation, and I am passing
input number five. So what will happen
in that case? In that case, you know that
initially top is minus one. Because if it is empty, first off on
incrementing by one, so that becomes 0 and that net position will
be pushing my element. That is, I will be storing
file in the subscript 0. Therefore, what will
happen in that case? Subscript 0 because we
know that the van I increment by one becomes 0. Subscript of that is
area subscript 0. In that place, I will push, I will store the
element that is five. So what will happen
in that is their top becomes to be the men by one of the top will
be equal to zeros. That is top will be roughly at 0th index and then
this position. And you will be stored
in the number of fights. So we will be stored in
here at this position. So on. So now next time
actually I have to simply push another
number, say six. Again, my top will be
incremented by one. So then we will
store number six. This position, this Eddy. This is how we'll actually, we will be performing
the push operation. So what about the pop operation to be not that we
don't have any option in case of Bob if
there are 56 elements stored in the array
in the stack. So we don't have any, we don't have oxygen to form the value which was
poached very first. Remember the pop
operation is performed, it will be pumped,
it will be posted, popping the last element,
and accordingly, so we know that the stack
follows last-in-first-out. It is the one which
is pushed very last will be bombed very fast. We have to pump
very first element. That is here. So we have to perform, in that case what
will happen actually, we have coupon above that
much amount of time. The 0th element. So you can understand the
0th element in the fog, the very large and it was the one which was
pushed very first, but it will be found very last. Network stack is called
as last-in-first-out. It obeys last-in, first-out
on forecasted Pascal. So this is what happens in
case of the stack for Chen. Also for the fall, what we will do, we will first
off, I'll retrieve United. It is referring to
the last element. So that value will be, will be, will be retrieving the top one. Even return the value
which we have written. Some video of him. This is how we perform
the pop operation. So let us start and
directly write the program and then we will
understand it better. So this is the program
I have created a new project and
the code block ID. I paused, I will be running. I will be explaining your line-by-line
instructions in C plus plus, and then we will
be executing it. And then it will be also seen the program written
in the C language. First of all, there is no much difference and C
and C plus plus because one difference I have used
here just blueprint as to display as well as to input the functions which are called for C and C plus
plus are different. Rest all the things, all the implementation,
our scene. You will understand once
you see the program. So this is the main function. This is the C plus plus file, in which this is
a main function. We know that whenever we execute the program entry point is one. It doesn't mean function. Line-by-line instructions will
be executed sequentially, which is dead inside
this main function. So first-off on what I'm doing is I'm declaring
these variables. The name you can see
option and item. I'll explain you
what is the purpose on them once we use them. Now, this is a simply display
message stack using arrays, since we'll be
implementing stack using Eddy in C plus plus. And this will, let me explain you what we will be doing first in the program. Since we know that we
will have to perform this bookshop lesion
pop operation, display, exit, all these
operations we have to perform for the stack using EDI. So in that case, usual users should have the flexibility to
choose the option. So we should ask the
user these adoptions. That is, if the user
press one and you don't want to poke on push our
patient if he wanted to perform pop
user to enter two. If you don't have to hop on. In that case, you don't
have to enter at least so all these things we will
mention to the user, so that user will be flexible. User can do anything
which Bob IQ, and if you don't have to exit, we will provide
that option also. So simply we will be
using a switch case. And I didn't get an ink, the switch is in my one. This, you can understand. This loop will be running
infinite number of time. The user don't mention
to exit that option also have provided because
whenever I am writing while one that
means a loop is going on, it is running in finite time. So you have to ask you, is that actually the user
have to come out of the loop, don't want to perform
any operations. And the user is supposed
to press any number. And accordingly, you will create the case for it since
we'll be using which case, it will be getting the
matching case for that. And we will be writing, we will be writing
a few lines of instructions to
exit from the loop, to come out of the program. Do exit from the program. So this is how we will
be doing enough program. This is my L1 and you can see
Environment quarters there. All. I'm having my switch case here. In this switch case
actually better. And you can understand
that it said that I'm displaying
different messages to the user that
Warhol options are then depending upon that user, have to enter that value. These values I bought actually since you know that in
case of the switch case, what we do, It's a
purpose or switch case. The purposes that first of all, if the user is having, have two 2's from n number of cases actually have to
perform a number of operations. So depending upon
what users want, we can simply create the
cases for that much time. So having five options he was at evidence is
having five options. So we'll create five
different cases for that. Accordingly, we will ask
user to enter that number. So you can see here
that this while-loop, I've just displayed this
message that is the smart, use it as having this option and user is supposed to enter these numbers for performing
corresponding operation. And then this option actually that is which
I will pass in switch. This is option that is 12345. That is the option. And you can see this is the
medieval which are declared earlier that I will
make US feared. In this switch case. You can see in the switch
I'm making the use of this option that can be 12345, whatever the user provided. And then accordingly, I have
created the cases, case one, case two, case five. And finally, we know
that in such case, the default is that if
it does not matter, then it will go to
the default case. This is what happens in
case of switch case. Let us see one by one, which operation for
peak display an exit. Now, what will happen if we have poor performance and
user one element? So you can see, first of all, I had in this program, I have first of all, creating the stack is a stack
using the EDI. So I will be creating the eddy, that will be the stack. So yes, this is my
start off my program. Since it's a C plus,
plus some project, I have to, I have included
this header file I O stream. This is what CNC out I will call these functions we not seen as stool input from the console, cout display on the console, input, output operations
functions I'll call. So I have to include
this header file, then this namespace, std, then whatever function we can use returns under
this namespace. And then you can see Stack using edit that I have
created this tack. In my case, I want to store all the elements
of the stack on the data type integer
that created the stack. You can see it's a simple array. Since this program
and stack using EDI. That is the reason
I'm creating the EDI. And this is depending
upon your requirement. If you have to
store in this stack all elements as the
datatype breakfast. So instead of int,
you can give it, as you can see here. I have given you up. If you want to store character, you can get scared stack,
I'm just good at it. And this max, so max, which is that actually I am
hash defining some value. So here I will just
mentioned hash. Define max. Suppose Cathy, you can define to
any value depending upon how much size you
want in case of stack. In case of the ADA, you know that whenever we are implementing the
stack using the eddy, we have to define the size
homeless size you want. What will be the
size of the stack? You have to mention
it initially here. You can see, because
you don't have any option to change the size whenever you are creating and implementing the
stack using EDI. That is, whenever
you are implementing the stack statically, statically we cannot change the size if you are
using the eddy. What if you have two teams? In what, what? If you want
the size to be flexible? In that case, you have to implement the stack
using linked list. Since I'm implementing stack
using EDI, the sizes fixed, I cannot change it that
at anytime actually. As I told you for the push
operation and the stack, the school and we are
performing the push operation. What will be the
scenario in that case? We have two Falstaff
while check whether the stack is full or not
in the stack is full, we will be simply
giving the message. We cannot perform
the push operation. And another nice that
you can simply add one more eddy that the size will be the double
the size of the old area. And you can copy the content from the old array
to the new Eddie, and then you can pop on boxer. In fact, you can see how
much time consuming it is, how much memory
it will be taken. Here I post-op, while we will
not go into that a manner, we will simply display the message stack is full so you cannot perform
the push operation. So the best actors
using a linked list, because in that case it is
irrespective of the size, you can simply you don't need to bother
actually about the size. You can. You can
run time on site. Who can runtime? This is the advantage of
stack using the linked list. Now coming back. Since I've created here, you can see here by the name
stack on this Good Eddie. So we should give them
meaningful name so that you'll understand
what you are doing. What is the purpose? This maximum, this,
I have defined this isotope on the size
of the stack to be Cauchy, so I cannot exceed that size. I have to maintain the size
for forming which involve I always have to ensure that
it does not cross the limit. Let's see. Now, let's come to
the main function. You can see here this
is, as I told you, this ad is so here
we will be storing. This is just tack. That is the area in here. We will be performing
the Pucelle box, so we'll be storing elements
in this Eddy in this stack. Now, the main function, yes. So suppose the user wants to
perform the push operation. User is giving, is SCOM. Just entering one. What will happen in that case? Since this, these 12345
all list this option, all these values and we
will accept an option. And accordingly, the sweet time passing this option in this Mitch and accordingly
the cases are there. Therefore, the user enter one. This condition will
be satisfied, right? You can see here it is giving since this is
a push operation, so therefore we lost you. So first of all, what
element the user is supposed to be wants to push. So therefore, I'll ask user
enter element to be pushed. In this time. The user will understand
and then you will give that element and that I'll
be accepting and call this. I have created the new project in the code block
IDE for C plus plus. This is the program which is written in the C
Plus Plus language. You can see here we are having. Here I've just
increase the font size so that you will
understand it more better. So we know that whenever
we execute the program, the control comes the
very first function, that is the main function. The main function is
the very first function whenever you execute
your program, as well as C plus plus
mean as an entry points, that will be the very first
function to be executed. Line-by-line
instructions will be executed there inside the
main function sequentially. Let's understand
the program now. What I have done
initially when I come starting of this CPP file, that is C plus plus
file, I'm first of all, including this header
file that is hash include iostream
in C plus, plus. This iostream means
since I took, I will be calling CNC output, inputting on the console
for display on the console. Before I have to include this iostream input
output stream, which will have
their declaration of this scene and CEO function's
input and output functions, which tells me call
it, which I'll be neutral women to induce offered. That is the reason posts you have to decline
that header file. I'm also using the
names namespace, std, so that if I want, I can make use of it. And you can see here
that this is a second. So you can see here I'm
defining mass to tidy. So what is this max
that I will tell you? First of all, since
we are implementing, began implementing
stack using the edit. So therefore we have
to create a array. And you know that in case on
the Eddy the size is fixed. We have to mention when we write the program initially we
have to define the size of stats because
runtime we cannot change the size of the stack because the
size of the stack is, it is, it is not possible to change the size
when your program, in particular tree
that has only been on leave and you implement
the stack using linked list, which since we are implementing the stack using the array, we have to define the size. And that will be
fixed throughout your program and your
program will be run. So that is a disadvantage
that you are not having the flexible size if you are using the area the
size is fixed. So you have to take care of it whenever
you are performing, which we will see ahead. So therefore, since I'm
creating a stack using Eddie, Eddie by the name stack
underscored Eddie. And I since I have to store all the limits which are
of the datatype integer. So we know that first of all, the elements, all the elements will be having the
same data type. So since I have
to store integer, therefore I have declared here integer if you want
correctly, you can, instead of n, you can write it as depending upon
your requirement. This size I'm giving you this size I'm already
has defined it. You can change here and
starting on the program if you want to change it, change to 40. But Runtime Window program
executes, you cannot change. You don't have that
option whenever you are implementing it using an editor. Now, these things I
have done initially and you stop using it as minus one. We know that we
have already seen earlier that when
the stack is empty, first of all, we will
be declaring and initializing the top
will be minus one, indicating is empty. That is a thing. And therefore
initially this thought which I have declared
as on the datatype and we will be having the value to be minus one when
I initialize it, indicating the stack is empty. Now, let's move on to
the main function, because the control will
come from here itself. Now this variables
I have declared, you'll see that we
have made use of it. This is simply a
display message stack using EDI, then this mile loop. So what I'm doing in my program, let me just tell you post. So since we want the user
to have these options, you can see here push operation for peak
display, an exit. And I see all the
details about it, how the functionality goes on, and what it will do,
what is the purpose of each function and the
lines of instructions. So don't worry about that. So we are displaying this
message on the console. So what we will
do, these options are there if the user wants to perform different
operations which are there for our stack. And we add asking you, these are the options
for this bush Bob. So what we will do, we will use us which case? First of all, we will switch
case in this while one, meaning that this while
loop will be iterating. And you don't ask actually, build a user, don't
want to exit. A user is having
all these options and music and play
with these operations. Analyst user don't want to exit if the user wants to exit. That also functionality
we have done. That is the reason we're
using this myth case. We had asked, we are mentioning these are the different options, 12345, I named the
variable name opportunity. You can accordingly simply enter these options depending upon what operation you
want to pop off, even if you want to exit, you can enter five. And in the case we
have implemented all these functionality which
are dead bodies options, which that is a purpose
This mitigates, might be running IT environment. So this loop will be going on iterating till the user
don't want to exit. If the user wants to exit, then simply we have also
provided that option and then it will then relax it. And we have implemented
all these operations. So in the cases accordingly. So let's see, that
is a reason I am running this while one
inside this middleman, that is a switch case. These adoptions
supposed to be are displayed on the console
so that users will understand what you have to enter to achieve Bob
operation accordingly, these options which are there, you can see I'm simply
using C and C and is used to except the input from
the user on the console. So this is the variable
which I have declared here. So this is the media
declared here and making us off with
whatever user enter, whether it is a one on
whether 2345 numbers between thrombin to find user will
enter and that will be elected variable,
that is option. And accordingly, I will
pass this, switch, that option and I have
needed the cases 412345, whatever is there I
created for that. You can see here
case one, case two, case three, case
four, and k is fine. And if the user don't enter any of these options by default, you know that in switch case we have this option and it will go here saying that user has
entered the wrong option. Let's see, post for
the push operation. If the user wants
to perform push, user will simply interval. Therefore putting this
which case will act, submit this case one will be satisfied because he
was I'd have entered one. And therefore you will have
to poke on push operation. First of all, you as
opposed to ask the user to enter the elements that
users have to foot. Therefore, you are asking you, is there that right
here you can see an element to be
pushed in this stack. So user will understand, user will enter that
element and you are calling this suggest I have
modified this actually, which I have written
it as scanf. I modified it to scene
because we are using, we are implementing the
code in C plus plus. So therefore for C plus plus b, you'll see in NCL, seen as used to accept the input on the
console from the user. If it was the C program, then we would have used, not seen actually, you would
have used that scan f, which I've used allele giving
the farmers as a fire like this. This is a V. If you want to give input on
the console, you use scanf. You mentioned the formulas
specific essence, we want integer, the item to be inserted, ability to type in
the full performance. This is format specifier, network poison the
different bombers specifier are there for different term datatype and this item and we
have to pass and present I can You have
to pass in this manner. Instance, I'm not writing
the code is for C plus plus. Therefore, this is the
function for that. That is C in C and is there to ask the user to enter, the
inputs are intact. We have to not mention the
hormone specifier directly. We'll give this variable
name that is item. That item the user enters, we're collecting an item. So suppose the user enter five, so that would be a parsing. You can see I'm
calling the function and passing this
item, that is fine. So therefore the control
goes to the function. Let us to the definition of
the function and this value. Let us see. What will be the definition
of the push function? So we will move to
the definition. The control comes here. You can see here push, this value will be passed to this function as an
input argument. Here. This will be very human. So you can see here this five is pass and this is
on the datatype. And since we want to simply
push onto the stack, we don't want to return
that would return. You can see here this is a void. In order turning anything we have to simply
pushing this time. I have already mentioned when it might be at pitching
in the stack, we have to always take care
about the size of the stack. We have to always make sure
whether your stack is empty. You have to make sure and
then your stack is not cool. If the stack is not full and only you can
perform the operation, then only you can
call the function, then only you can watch any element if your
stack is not quick. If you don't check
this condition, you can understand the status Fool and you're still pushing, you're not checking
that condition, then the old law
can occur and it can behave half as a
result of a white guy. You have to always
give this condition. So what is this? I'm calling one more function. This is by the name stack
full so it fits in paycheck. My stack is full or not. It will return accordingly. So what should be the definition mean old and will be the stack. What we have, we know
that the top is equal, equal to max minus one. That is my nobody who are top, as you can see here,
suppose I am having, this is a stack of this ice. I'm doing hash define
match tool six elements, and you can see
indexing will be 0. Suppose my stack is food. Despite that are all that I have stored for five more elements
that I have stored 678910. Therefore, my topic
will be fine. When I'm calling
the push function, I'm passing some value, say Bush, and I'm passing
ten value in that stack. What will happen, my
talk in that cases. And still I'm not making I'm not the charting whether the
status will in that case, the older flow will
occur because there is no size I'm eliminate will have half as many saw that we have Paul this
checkered actually. And that is a reason. Then the stack will
be called whenever my talk will be
equal, equal two. You can see here this iss
what I have given here. If there are six hash, define max six actually therefore
I've created assess stack of size six. Therefore, since in an array, indexing starts from
0 to n minus one, therefore it will
be from 0 to five. You can see here therefore, if my thought is equal, equal to max minus one, so that was six
minus one becomes fine because the Internet
indexing starts from 0. Therefore, I have to
always be in short if my opposite equal
to max minus one. In that case. It means that stack is fully
in this function itself. What will be the
definition of it? See, this is this I
have defined here. It will return the integer
whether yes or no, the stack is full or not. Dancer will be rather
one on it will be 0. Therefore here I'm checking if OP equal equilibrium
x minus one, then simply return one
else and return 0. So I hope you understood
what I am explaining you. Therefore, coming back
to this operation. Yes. Actually, if my
stack is not put, in that case, what will happen? Definition that I have
implemented this. It will return 0. This stack is not full and this condition would
not be satisfying. That would be weekend push any element because
the stack is not put. In that case what I told you what we're supposed to do first, we are supposed to post increment the top by
one. We have seen that. And then we will add
that base actually then, which the user Wanted to push. And therefore, you can see here, since we haven't created the EDI on the datatype in by the name
stack on this area. And more to stop actually, initially top is minus one. But now at this line when dog gets incremented
by one becomes 0. Network stack, stack on
Discord add a subscript 0 is equal to item that is despite that would
add 0th index. Actually this guy
will be stored. Therefore at 0th index. What will be stored? This
five will be stored here. Because stop is incremented from minus one, incremented by one. The top is 0 and liquid at this place I'm
storing this element. This is what we are doing
in case of the population, and then the stack is full. This condition will be
satisfied if the stack is full before pushing this candy. Before performing these
operations in the stack is full, then this condition
will be satisfied. So again, if I find poaching, if I'm already put all the
elements, my stack is full. Now again, I'm pushing
some more elements, then it will come here. This condition will be changed. Yes, it is full. In that case, it will
enter inside this block, it will give me Stack
Overflow and through the turn from non
perform this operation. So this is only in the
case when the staff. Is this condition we have
seen in this function. We are checking if
topic will equal to max minus one and
only this full, this is the simple
push operation. Let's move on to the
case for the push vet in me trying to understand. So this is an then I
have given this big, you know, that in switch is for each cases we're supposed to give the break
in this manner. Because if you don't give, the next case will be executed. So you don't want that
because there are different, different functionality
for different cases. If the user wants
to perform push, only push should be perform. You don't want you
when you've been not drive until and unless user
don't enter that option, you have to mention the break. Then for the pop operation, let us see now what next
for the pop operation. So if the user wants
to perform pop yours, user will enter to switch. In option there will be two. So in this case, two
will be this fight. And therefore, we are calling
only the par function. You can see I'm not passing any arguments since we
don't have any option. The last element
will be on Nipah pt. Depending if you have
to pop all the elements you have to call
that much amount of, you have to call
the pop function. That most amount of time. You remember, just last
element will be formed. That what I'm calling pop, the element will,
which will be bought. So let us see the definition. So what I'm collecting
in this video, but this is item
which I have declared as the datatype
int I'm collecting here in this spot.
You can see here. Yes. So let us see the definition, what it is doing and how it is returning Information,
Bomb devalue. Let's, let us go to the
definition of the pop function. So it doesn't build definition. So again, One more thing. Whenever we are copying, we have to answer check
whether the stack is empty. If your stack is empty, in that case the top will be
equal to minus one, right? No elements present
in the stack. You obviously you
are not supposed to fall because there
are no elements. So you have to
check before before writing the instructions
to perform the job. You have to, first of all check whether your stack
is empty or not. I have tagged by the
stack is empty or not. Let's see the definition of it. It is what will be
the condition we have to check? The
stack will be empty. We know that this
is in addition, if topic will equal
to minus one, that means the stack is empty, so it will return one, it will return true if
the stack is not empty. Therefore, in that case your
popularly not minus one, it will be having
some value like 0123. If there are some
elements present. Net case it will return 0. Now moving to the fall. So therefore we are
checking this condition. If this condition
is not satisfied, that means the
stack is not empty. There are some values
present in it. Now you can fall. So therefore, this condition, this will not be
executed because this condition is not
satisfied in that case. Therefore, what will happen? You are simply this instruction will be executed. What is this? If we have football,
first of all, we have to retrieve the
value in some video bill, and then we have to
decrement the top one. So simply I have made
it in my online. That is what I've done. I'm simply using this area. You can see n subscript
minus, minus. Minus, minus means,
it means you, I'm doing the post-implementation,
that means fast. It will be acting like this, like stack underscored,
add a subscript. In the next line. It will be topic while to talk minus one. That means we know the
basic thing whenever it is opposed agreement that
variable will be making use. Variable is first used and later variable will
be decremented. So therefore, what will happen? I'm returning this element that Is that better
their toxicity frame. So the top will be referring
to the last element. So that will be, I am returning that value. So suppose that only I
have pushed five on me. Now whenever this stack on
this Good Eddie subscript, only one element on the app which you know that in
that case they're talking Vizio stack underscored
at a subscript 0. Subscript 0 is what
actually, you know, that the top or
top is actually 0. So what will happen? It will return the element
that is five and then I'm decrementing by one because it's supposed
implementation. So top is 0, count becomes minus one. Again, see, instead of this, you can also write like this. Item, like this. And simply item is equal
to stack underscored. Edit subscript. Simply minus margin. Simply return. You can also write
in this manner. You can see I'm
declaring an item, whatever the stack underscored. Subscript office stop
is what actually suppose you had only one element
is present in the stack. So in desktop is you donate
to stack underscored, add a subscript 0. Suppose that element is only
five, which is present. So therefore it
will be stuck and it's good at is absolute 0
will be giving me the answer. That's fine. That either I'm collecting in the variable item and then
I'm doing talk minus minus. So Tom becomes from 0 to
it becomes minus one. When I decrement by one, then it becomes minus one and
I'm returning this fight. This is the thing which
I had converted into. Second one line. You can do simply in
this one line itself. Instead of all these things. Again, choose whatever you
want to do depending upon. Now, this is how we
poke on the ball. Now moving to the next
case and now let us see. Yes, now it has return me some. And you can see here, the bank is returning this
element that is fine. Datatype is in. Now
what will happen? Therefore, this value is
that element is returned, is five, say Nike's. Therefore, we are collecting
in the variable item and we have seen a dissolve
the datatype integer. And we asked what
we are doing here. We are simply displaying the message bar value
and that item name. That is the variable
name that is item. So therefore that
element is what files. So you will get simply
BOD value is fine. You will get the element name, element which you
are copying just to display so that he was
OK and make sure yes, this is a correct
value we just bought. It will be the last
element which will be false. If you want. This is how, depending
upon the requirement, if the user has English
five elements in the stack, user will enter one and then
we'll put some element. And again, user had to
perform push operation again, the user will enter one
again with some element. Again, the user wanted
this five times. The user have to
push some element that will be pushed
in this stack. And after that, whenever
user one to pop, the last element which
was pushed will be four, will be formed the very first. So this is how it works. So you can simply write
the program in the same. I'm not in C plus plus
N venue executed. We will see how flexibilities, how it will store, it will relay motif last
element which is which will be formed very
close and the very first element which is
pushed will be pumped. Very last military this. Now next, let us see
the next operation. That is, we have seen what
is the purpose of the buses. It could return the very
last element on the stack. It did not pop. It will do the same
operation what Bob does, but it will not pop the element. It will simply return
the last element. It will not decrement your
top whenever you have seen in the fall and he was
returning the last element. But we must also decrementing the top in case on the peak, maybe simply return
the last element. You will not decrement dot dot. So therefore, here you can see what I'm in the case
three will be satisfying. I will switch on, switch d will be passed
case we will be matched. And we simply displaying
last element in the stack is the speed function. We're calling this function
because this function simply return the last element
which is present in the stack that
only I want to print, and therefore I'm calling CL. And let us see what
peak middle written obviously should
return the element of the datatype integer
because we're storing the stack with the elements
of the datatype int. So it should return
me some value. And therefore I'm
displaying in this manner. So let us see the definition. What we have to write
the instructions is z. So this is my peak function
3. Stack using Linked List C++ Session2: Hi, welcome to the new session. That is stack in data
structures and algorithms. This session we've been
writing the program to implement the stack
using linked list and steep as plus realized
as well as we will be also executing it
on the woodblock ID. I will be also mentioning you the minor difference
if you will be writing the same program and C language. Before moving to
the code block IDE and raping the program,
Let's understand it. Revise the basic things which are required prior
to writing the program. We have already seen
when m and we have implemented a stack
using linked list. In foster one, we
know that stack follows the principle
that this last in, first out, that means the
element which will be pushed lastly will be
formed the very first. And we know that in
case of this tag, the push and pop operation, it occurs at the same end. So here it will be at two. Since we are implementing
using the linked list, we know that it is
efficient to perform push and pop operation
at the beginning of the linked list
instead of harmony, which in bulk, and we have seen the problem if we perform which involved at
the end of the linked list. And that is every time for each portion of the linear element we're
programmers from starting with the end of the
list and then we have to insert that element as
well as for the pot. If we IPO for me, that is if you're performing. And then we need to also
perform pop and the end. And that we have drivers. And then we have to delete the node that is delete the element that
is pumped up illuminance, you can see there is a reason
in case of the linked list, if you've seen it, we are avoiding to push and pop at
the end of the linked list. Instead of pushing and popping, let us, we will be
inserting and deleting the node at the beginning
of the linked list. I hope so you have gone through the previous session of
the linked list wherein we have seen that you have seen how to create
the linked list, singly linked list and
different types of meaningless. So here we're only making
use of singly linked list. So how to insert a
node at the beginning? How to lead in order to link these operations
will be required. Also, I have given you in
the earlier session that assignments to perform
these basic operations. I hope you've gone through the linked list session and that will be very much helpful. If not, I recommend
you to go to bed. So let me see here. Insert the mortar the
beginning how to delete. So here in case since we
are implementing the stack, the Insert means
pushing the element and deleting the node
means popping elements. We will be using all
those instructions which are required in the linked list, all
those operations. And we will be seeing it here. What happens in each allele, but stack is empty. That means since we are
implementing in the linked list, we know that to implement
the stack using linked list is implementing
the stack dynamically. That means you don't need
to bother about the size. You can decrease the size, you can increase
the size runtime, you can allocate more memory, you can deallocate the memory. You don't need to bother about the size as we have seen when we implemented the stack using EDI that decides
we have fixed. Before executing the program. You cannot change the
size if you have already, you already in case
of stack using any of the sites in your
program and runtime, you cannot change the size. So that was one of the
disadvantage when you implement the stack using letting or
in case of linked list, the advantage is that you
don't need to bother about the size and how you will be allocating
the memory simply, you will be calling the
malloc function in order to allocate the
memory in the heap. And for the node, whenever you have to
push any element, it will be simply first of all, allocating the memory for that node and then
pushing the element. We know that in case
on the linked list, the nodes are present. In each node will
have two fields. Boastful will have the data, and the data type that
is np TO characters. But we know that all the
limits on the nodes will have the same datatype. It is either if you are
filling all the modes in V2 and then it
will be integrated fulfilling all with the
corrected will be correct. But the next field of the normal appointed with the
next node so that we have seen all
these basic things. We have seen. You have a word
in the linked list session. Now, consider your stack
is empty in this manner. And in that case we know
that pollen in linked list, whenever the linked
list is empty, we are representing
a start pointer that will be a high head point, then it will be also not. But when we start creating the very first
node, in that case, we look at the memory
and that stock will be pointing to that portion
of each and every time. We have to keep into account that the staff will be always pointing to the first
node of linked list. Here the start in case, since we're implementing
using stack, we have to always refer by
the name topic of staff is a reference point
wherein we will be pushing and popping me know, in case of the stack. Though, stack is empty, that means there are no
nodes which are present. Because we have
created the Lao and Blackboard will be null. We represent instead of Scott, you're using the name has stopped since we're implementing the stack will be null
since the stack is empty. Now, what will happen next? Whenever the user will
call the push function, that is in this manner. The succinctly. Suppose you are having this calling function, and here we will be pushing the element of the
datatype integer. So suppose a user
is boiling this, use them on to perform
push function and use it by seeing
this element ten, user one actually which
distend and this this stack. So what we have to
do in that case. So in that case, first of all, we have
to create unknown. Since we are implementing
a stack using linked list, we have to create the node. Yes, we have to create a node
and that is dynamically, that isn't the thing that we
have to allocate the memory using manual function that
will be the postdocs. You have to create a new node. And then what we will be doing, we will be simply, we know that it said that for speed will
be having the data. So we'll fill the
element with the data. That is, it will be here. Then we'll be
filling it with ten. And what next we will be doing. The next will be simply point to the next node since it
to somebody first node. Therefore, we know that it
should be null in that case. Let me show you
how does it looks. Initially our stack is empty, then focus on so when
you create a new node, what changes will be happening? Let me see that now. This is the thing when
we create a node, when we add a node,
in that case, what will happen first of all, stack is a stack was
empty naturally, but we have the user. The user wants to
push the element. Then we have seen,
so we are creating this new node dynamically
allocating memory. So this is how it looks
logically our stack. So this is the new
node with them, given what you will do your
fill that element one field, this is one node we know
in ESOP linked list. So the first field will be paid with element which
the user is passing, that is ten and
the second field, since this is your first, note that with the second field, you're not having
any other node. It will be, it will not
have any at this node, it will be simply,
you can see here. Now what you have to modify. Now you can see this
is now a stack. Stack is not empty,
but stacking stack, you have already
created the node, you have finished element. So therefore, you know
that the stack is reported by the thought should be
pointing to the body. It should be pointing to the very last element which
is present in the stack. We know the stack follows
the last impulse down. And so therefore since the
topmost null initially when the spec was empty now your
stack is not post-Snowden. Bob should be pointing to this node that you have created. So in that case, what logic is required? We will also see in the
program I just mentioned he has for your
explanation purpose. So this is the launching. This is the definition on the push function matter
if this is your new node. So I'm not written, not shown how to allocate the memory for
the new node we will see in the program
radically when we write it in
look or block IND. This understanding we
created a new node dynamically by using
malloc function, and this is your new node. Once you allocate a memory, then there are two
appeals of the node. The first field is beta and this is item
at this span will be filling this ten. You're feeling this data
with this value ten, which the user pass. The next field of the
new node is what next? We will initially, since
it's somebody first node. You can see here this
is a forest node. And therefore you can simply, you know, the next
and then next. The second field of this node should be null because
it's still false. No, we don't have any
I didn't not know. We just should point
to and therefore, we know that it is a null. Therefore, we also
know that top is also null initially men
mistake was empty. You can simply write
in this manner. That is the new node next
is equal to the new node. Next is equal to five. That means simply, you know, negative office multicore,
this new node next. That is, what is the next? If it's only actually
it will be null itself. Now, the next thing, what you are, what
you need to modify. Now since you have
added one node in the stack after the talk
Chuck point to that node. So this is a new thing
which you have to do. Your next line of orbits
you ever do that torque is equal to new node. Here. Why we are doing
all these things? We know that now the talk will be since now
the stack is not empty. You are having this
always known presence. So that should point
to this new node. So in that case,
what will happen? This will not be null. So it will not be equal. It will be not null actually. And you will be having
simply the top. Here. This is your top obvious now
pointing to the new node. So you have given in this top is equal to
new notes so that this new node which
you have created and not simply write
equivalent new node. You can see Dr. B. Pointing to the very first node, which is what we
have to also ensure that we have to do this pushpin. Recall the definition of the
push will be in them and I add a node at the beginning of the
linked list next time. So you can see here
not only one node is being added in your
room stack that is, one element is pushed
in your stack. Next time when you
render user again call the push function
and use a need to push, say the value 20. That is what you have to do in the implementation
on which function. We know that since
in our linked list we have to add a
node when we call a V&V afterload would
approach and then we have to simply add an order depending
of the linked list. So therefore the, it did you
see the next time the user, also called the which function and user needs to push this 20. Warfarin happened. So obviously this 20, We have to push here
actually at this place, we have again create
the memory new node. And then we have
proof in one field, first field of the node with
that 20 and what will be the second p. So what we have
to take care for that? We know that since we have
to add a node each time, let me create a new node. And that node in this stack. In that case, we have
to add these nodes. I'm thinking of the
linked list network. If you represent this node, this one, this was
the president. This is your logical
stack if you simply, I have also represented
in a horizontal manner. So this is your vertical
manner because each incus, since we know that
in case of stack, it will be represented
in this manner. But we have seen in the linked list, this
is your new node, which initially when you added this force node and next
time when you add 20. So we know that since when
we push the element 20, we have to perform the operation to add a node at the beginning. So this is your personal menu. I wanted to add the
node at the beginning. Then what should it be?
The case like this? It should be In the next node, which just a second. Therefore, you have men again, he was called up which
function and pass 20. So this will be added when you represent these pink tactility
in horizontal manner, as in case of the linked list
than this 20, which is bad. This node which you
create actually will add at the beginning
of this in the linked list. Initially only disperse,
notice present. Then you add your the egg, the next node actually that is a new node at the beginning, that is not yours. So you have to not after the second node,
that is a new node. After this node you have to add at the beginning because
we know that whenever, if you had calling
the push function, we have to simply implement the functionality of adding
the node and the opinion. So each time on DNI, I've been simply added the new. So this is the node
which I'll create. And then this 20 actually, so this will be the
new node in that case. So therefore the
new node we will be adding beginning of
this node actually, and therefore this
will be my new node. I'll create a memory upon the new node and I
will fill before spilled on this node with which the user is
providing that is 20. And what will be the
link part of this node? That is, we are referring
it as by the name S. Next, it will be simply
the address of this node. You can see that again when
I create an user again, say Part D. Again, we'll create a new node. And again, we're
going to fill it with the force field with the data which
user is providing. And the next field will be
the pointer to this new node. Because since we need to
make sure that whenever we are pushing the elements, we have to simply poke or
in case of the linked list, we have to add a node
at the beginning. So we have to not know each time the node will be
added at this place. That is this. Now you can see
here, since we are, when we are users pushing 20, we're simply creating the node and this node at this node. Then we represent, in that
case what will happen. Therefore, the new node,
that is this node, this it's linked part, will be simply having
address of this node. That is simply, you can see that new node link
will be equal to. So what is the
address of this dog? Because 100, So that
whole new node link will be equal to talk. This one. You can see your new node. Next, we are representing
the by the name is next part of the node and
it will be equal to top. You can see here when
we do in this manner, then what will be happening? This will be the thing
that is a new node. Second part is the link button. There is a next we will have of this node actually
that has stopped. So therefore it will have 100. And you can see that new
node link is pointing. Now you again, you have
to want to change. You have to do sophomores. Pointing to this
node, captured point. We know that we have
to make sure that top point to the new node. That is the last node
which has been added. So the last node is this. He said, Notice this one. So therefore, what will
be the instruction? The same thing,
that is this one. The top is equal to new
node, not be pointing. This will be this will
be the top on this one. This we have done. Again back to me then
we have seen that against how it in this target will look,
look in this manner. So in this stack it
will look like this. This is joint D is Edit. And you can see here this
is the horizontally form. So the same thing, that new node which you
have added actually, and we have seen that a new net, new node next Fed
is linked bark will have the address of this
node which we have, which was computed earlier. And then this will be updated. Ofs is equal to
new node and depo not binding to this mode. So you can see
that we are making sure that every time
whatever node we add will be pointing to that node B and making
sure that linked list, the node seed, the standard
was already false. Then the next time we edit 20, so we are adding at the
beginning, that is before this, this node, we are
adding this new node, which we are creating the ID before this node and
not after this node. So that is we're not
an ID at the beginning of the linked list so
that we have not private. We're not, we're
maintaining the adhesion always at the beginning so that we can meet
weekend and China, we achieve a good diet that
is very much efficient. That is, the time
complexity should be big. One. This is also a next time. If we want the users simply
calling the push function. And again, he was user again, foster to user one to simply, again and again push
this cart in the stack. What will happen in this case? Again, you know that
what will happen again, we will create a new node here. Again, the limit
will be located. I'm on that new
node will be filled with for the next
belonged new norm, it should be pointing
to this node. Therefore, this will be the
condition that is a new node. Next is equilibrium. Request. Top is pointing to this. Let us know earlier node and then the new node
we have created. Now the top should be
pointing protecting mode. So therefore torque is equal. Newnode and NVD
present horizontally. That is, we're simply
adding making job Here. We are. This is just
a representation to make you and
explain more better. So within the stack, it
looks like this venue. Venue is simply represent
in the horizontal form, it will look that you are adding the thing that you
always at the beginning. This part, it will
be added before this node, this new it, an order will be added here
and you'll be modifying that link will be the
address of this node. And that is the
next part of that. And then stop. I'm pointing to
that node that is, whereas I told you,
this is how this works and how you perform
the pop operation. In case of the pop
operation, just a second. It will be known that whenever we are calling the function, it will return the element
which is being formed. In that case, we have to simply perform operation of the
linked list that is deleting the node and at the beginning of the linked list
bleeding the node at the beginning of
the linked list. So therefore, we
know that we are always having the
top pointing to the last element in the stack. So therefore we are
having a pointer. Is pointing always. Buddha, recent node which was been added so that
whenever we are popping that not only will
be what will be the change in water will read the instructions in that case. So suppose we are calling
the pump function and we have used two elements, we have pushed into the stack. So when we call
the pop function, we know that this will be
reported where the top is. Top is adapting to
the last element, that is the recent element
which was being added. Therefore, this should, this
node should be delete it. So in that case
what will happen? We have to also
make sure that we free this basement
me, delete this. So in that case, when you
delete this node placed upon, you should also be it sold. The stock. Actually, when
this node is deleted, should then be
pointing to this node. Let us know what it
is having them on US. Debt preferred stock
one, since you have to delete this node, you have to keep the
reference software. What we will do, what changes, what code is required? Simply the code is
that what we will do. We will damp node and
we're going to be simply third focus pointing
to this node, right? So we will keep the
backup of the storm. That is TMP. So I'm just explaining
in short the program even see how NADH has been
initialized alpha-keto. Remedy than anybody I
looked at the memory. So here simply big, big in the backup of the stop
with this point though that this M by M taking this backup because
I will be freeing it later. Now, the top should be
pointing to this node. So what I will do is
simply we know that Bob should be pointing to this node when we
delete this node, which is having twenties should adopt to be pointing to the normal it is having to spin up. The next part of this
nerve thought that it stopped early.
Is that a stock? Next, it will be simply we are having the
address of this node. How do we reach to this node? This manner that is the thought, thought me like this. In this, in this manner, the top and not
pointing to this node, it will be pointing to
this node that is ten n. What we will do. Finally, we will call the
function and we will be free this EMB, which is that. Therefore, since we
more business BNP, we wanted to having this
backup of this node. So this via freeing the memory, since we have to
remove this link, this is the
instructions which is required in order to
perform the functions. So I hope so You bought then
this node will be deleted. This will be deleted, so it'll be left with don't
need the SA node, which is having
the value as ten. So I will move into the
code block and then sinking with what we have understood till now
in our diagram. As well as the concept services, my code block ID. But I have created the project or the stack using
the linked list. And we'll be writing that. We'll see the program
in C plus plus. I'll explain you instructions
line-by-line and we will be executing it and see its
output will see the basic, all the operations which we are performing
butcher shop and what volt is required to implement the stack
using that LinkedList. At the starting of the program. This is your main.cpp. This header file we have
been through our program, we have written in C plus plus. So first of all, we have to include
this header file, iostream because we will be using the function of input and output in order to simply
inputted on the console. And two output on the console that is
in NCR will be using. So that is the reason I had
mentioned this header file. And we have to use
this namespace, std. Then we're simply creating a structure since we are implementing the stack
using LinkedLists, we know that in linked list
is represented by nodes. And notice having to data fields present in that
is supposed to be the data. And the next one will be a
pointer to the next node. And therefore we are taking
struct node pointer. And this can be anything
if you want to be the more Mitchell Hamline
guys character instead of and you can give it as an don't use, I will be putting the character, but here I'm taking it as NPV. I want my notes to be filled. We have the data
of the datatype. This is a thing then are you
can see here since we are implementing stack top is the
main thing which is MRSA, evidence Madden,
we'll push and pop. This is a reference point. So therefore, I'm using this top gustation
maintained in the stack. Initially since the
stack is empty, Nicola and a struct node
on the top is equal label. Instead of, instead of this
extra line in here also, I can write that pointer
top is equal to null, but I have written in
the separate line, depending upon how you
have to write your code. Now, you can see here now
coming to the main function, we have seen what kind of
files that require yes. This is a main function. We know that whenever
the program is executed, the control comes. The main, the main function. It says main function is an entry point to
start an execution on the programs and pull
all this comes in this main function and
you'll program is executed, line-by-line instructions will
be executed sequentially. So since we mourn different, different operations
on the stack like IQ displays all the one who came all these
options to the user. So therefore, what
do we have to do? How we have to do the coding? We will simply use
the switch case. And we will run a switch case. We run within my loop so that
you can see this my loop. And here you can see I've
used this switch case. If I stop on my arm using
my loop and I've given this one because I am
one minute to be born. It didn't repeat it into
performed iteration and iteration till it should
not end. The slopes are not. User, don't want to end it. So if you don't have to come born one to perform
any operation, then you have to put
them out on this loop. So I'll provide this option also off exerting so
that user will exit. User will act
accordingly and then use a mill exit from this loop. In that case, this option
I'm providing to the user, user don't want to
perform these operations. User can simply enter file. And in that case,
we will be exiting from the program will
be coming out of this while loop because
we have to make sure we have forgive the stop
condition to the user. So they're in order to
not go to the infant. In order that user don't
want to do anything, you do not want to
perform any operations. This is why in one and this is both options which I haven't be displaying
on the console. So I have c out simply. Here. You can see in the main function this declaration and we'll see how to make he was offered. But in the wild one, the message that he
was a well-known that to perform push operation. User enter one, then user
to enter two for 12, user to enter three for one user in before then display operation
user have to perform. If you don't want to exit, you usually have to fight. And if he was at grid display, then user had before. So these are the
options which should be up to Whiting and these options. And you can see a scene that is, we are collecting in
this medieval option. This is, the policemen
are making use of it. So we have declared
this as in Teach up and these options, that is 12345, these are the different options
that we are collecting. And we're passing in this
switch, in this manner, we are asking the user
is by using scene. By scene. The user
will give the input and that will be
collected in this option. And then we are calling in
VR a passing in this switch, this option, that
case one different. That is, since we are having these five options,
that is 12345. So therefore, you can
see that our five cases, case one case, two case,
three case, wooden case. People aren't One. One, What is the one
for push operation? If the user wants to
perform push operation, then you usually want
to poke on push. So therefore, in that case
the user will enter one, and therefore the case
one will be executed on switch and this display message will be there that enter the
elements will be poached. So we are asking
you to push water. Even user is supposed to approach that we use a
one proportion the stack. So that is the reason I'm
using Darcy in actually. And then I decided that
I'm making use Opera. You can see here this is all
the datatype and use them in any number and in item
you installed it. And then I'm calling the
push function and evaluate that pseudo support user is
entering ten, so their quota, and I use a 12 and
push their ten in this stack network I'm calling function and I'm passing
this item let us spend. So let us see the
definition on that. We have already seen one millimeter definition
in the non-profit itself. What we will do here
in case of push eyes, I have told you that
we will be first of all creating a new node. And this new node we are
creating dynamically. Therefore, you can see I'm using this malloc function that is
inside this malloc function, the sizeof struct
node because we want to create a memory
that will be done. That is the head of the
size of the stroke. No struck note is
having Though fields, that is force field as data. Next few days, next bit is
appointed to the next node. That question mentioned the
size and you can see here, I'm typecasting struck, struck node pointer because malloc
returns a void pointer. And therefore I'm typecasting it to the struct node pointer. So this is how we are allocating the memory
for the new node. No, we had also
checking that if you notice equal equal to none, I'm checking this can happen. This is good practice. Whenever you want to
locating them in summary, always check if it is or not. That means in very rare cases it will give you not only men, there will be no
space in the heap. In that case, only give you. That means there is an edit existing by creating
the memory in the heap, then only this condition
will be satisfied. But this is an exceptional case, but still I have to make
my program very good. Should be edited
checking for each, at each and every point. That is the reason I've given this is a good
programming practice. You have to make sure
whether it is null or not, because it can happen if there is no space and still you are using this new node and
the question upper, right? This checklist meeting
necessary, that is, if new node is equal to null, then it will display
this message. Now, once the memory is
allocated to this new node, then I'll fill this new node. That is, it is having
uses data and next, so beta will be bored. It will be done. And even in which the US
didn't have passed. So deaf wouldn't same thing
and the next will be taught. We have already seen that in case of the poaching
function, it's a second. Then we add pushing ten, then we stopped
will be new node. We have seen that
the stock cost of the new node next
will be the top, should be pointing
to that new node so that for this top is
equal to new node. I hope so you want this logic you have already seen
in our diagonal and so initially went and was pushed in bed this new weekly
I did them remedy for this node that
is envy-free ahead. And did this, we have
simply filled about cost of yield on the
node and the user. And third, and the second field. First node that we deserve, it should be dark because initially when the
stack is empty, the top business depth adopt this new node that is now
UI stack is not empty, this having only one node
that span initially, and therefore they should
be pointing to that and therefore gets it to
opposite building new node. Same thing on the net
is when the user is, I'm installing one to again
push any other element. Therefore, user will give
this value that is 20. Then what will
happen in that case? This new node will be created. We'll create a new
node, allocate, a new, allocate the memory
for that by using malloc function
means spin by 20. And the next field will be simply the address of this node. That is rather tough Was that, that is this instruction.
It should be. Then you ignore next will
be quieted down because we know that when we pushed this node red
and then talk was pointing dead end
when we have created the new node wherever we
want 20 to be pushed. Then therefore in that case, the next next field that is shouldn't be
pointing to the stop. The next instruction, that is, their will be new node. This node, the top
will be updated to this new node
and not destroyed. This is how we are performing
the push operation. Let's see other operations
which are present. Now. The user wants to
pop bob dot node, in that case, what will happen? Then in that case? In that case simply
the case two will be executed and we will
call the function. And also you can see
we are collecting in the item or this item
it is operated by. Now you can see item it
is on the data type in. Let us see the definition
of the bulk function. You know, if I'd never pop is very recent and humans
will be formed. You have to perform
population in such Germano and deleting them. For first of all,
it's a pump function and these other things
which we are doing. We have seen that
whenever we have to pop, we have to foster
fall keep up on the top in some other pointer. Because we will be
freeing that node, which is div at the
top is pointing. And that is the reason
you have to first keep the backup of their
talk to some point. You'll notice the
reason you can see here I'm taking one
more pointer that is PMP and fascia holding
before the popping Benjamin. First of all, I
have to make sure that my stack is empty or not. Why? Because if the
stack is empty, the stack is not
having any elements. There is no chance
to perform pump, there will not be executed. It should, we should not exit execute when the stack is empty because I didn't know
and demons and there is no point to anything. You have to don't take care of this and you have to check this whether the stack is empty. Gps and you have simply
exist from your program. Stack is not empty something
some elements are present. That means you can perform
the pop operation. And therefore you can see I have simply backup of the
stop with the CMP. Mr. Pickin here. Here is
pointing up this point. Now, what will happen? I've also. Element in some variable and after return
from the function. So you can see here the stem for data stamp is pointing management office
pointing its data. We're collecting in
this value and this is the datatype integer. Then you can see later on I'm
told I'm bringing this PNP. I'm feeling this
DMP edit off was pointing because I have to
simply delete this node. So if I'm calling for function, and so what I will do here, I could delete this node, is pointing to this
node which is having the element Asteroid
D. I delete this node. I have what I've done, I've
got in some another point, I'm simply taking the backup
of the stock to induct them. Then what I'm doing, I'm simply retrieve
the value from M, and this is 2003. And then I'm simply free. Then top is equal to top. Next, that is in this manner, you can see the enthalpy
is equal to talk. Next, we have studio,
we added an impact. I hope so you understood
also the pop operation. Now the next operation is
not amino, peak operation. In peak operation, first of all, it will return the element which is the last
element in the attack. Here first-off on the difference between he can focus that people only return
the last element, but in case of the ball, it will return the last
element as well as it will pop necklace tell
immediately delete that node. But here peak will not do
anything and just return the last time we'll display
what mass element is present. This is OP cooperation. Let us see the operations. So that is three
will be executed, function and medically
calling and imprinting it because it will return the last element of the
stack. So let us see. Here we're calling the
function there to speak. Let us see the definition offer. Therefore, this is
the definition. Just a second. This is my beak function. You can see here this one. Here. First of all, the return type is int, because we'll
return the element. We are checking if the stack is empty because it's
going to happen. There is no element
in the stack. So in that case we cannot return because
no element is present. Therefore, we have to make sharp before performing any operation. The stack is empty,
then it likes it. If not empty, that means it will return a pointer to data. That means they're
taught medical office. I'm pointing. You can see our top
is pointing here. What does after return this 20? So we know that it's 20 is the first pillar of this node and it has to be present in, by the name as data, the next pillar of the node is represented by the name
next what we want, we want only the
parts with the code. You can simply returning
data that is either type in, so therefore, it will
be displaying it here. So this is what we
are doing here. You can see you now in case of the case for that is if the user wanted to simply split, every user will enter or splay
operation will be there. So how to display? So
let me show here itself. So we know that logically in
this deck it looks like this when you add and you
replace it horizontally. You can see, suppose these
two nodes are present. You notice top is
pointing at this node. And whenever you have to
display your whole linked list, that is which is there
4. Application of Checking Balanced Parenthesis C++ Session3: Hello, welcome to
the new session. That is application of this stack in the ***
structures and unguarded them. Here you will be writing the
program for checking whether the given input expression is having the balanced
parenthesis autonomic. So this is very
important session because we will be writing
the program are the same and we'll be executing the code block ID will be
writing in C plus plus. This is the important
application wherein you can use this stack of books
solve this problem. Whether the given
input expression, it is having the balanced bed
emphasis using the stack. Before writing the program
in the code block ID. Let's revise
something important. Let's see the logic, what we should apply. I have just drawn here, thus stack, so amino
not nearly the stack. We will be using stack using
EDI vendor stack is empty. We know that the top heavy
that thought in case of stack, and we know that in stack
and pop operations pattern, the bush on the element will
take place from the top, as well as the port will
be also taking from them that the stack follows
the principle last-in, first-out, that is there any minute pitches
botched Verdi, lastly, will be
bombed very fast. Since it is an EDI we'll be using you're
adding, you know, that indexing starts from
0 to n minus one and all the elements will be on the same day that I'm answering. This has given expression. Suppose we are
asked to find that, that is this expression
which you can see here. Opening curly braces
then by multiplication, then opening round
record when people as foreclosing on record and
closing curly braces, you are given with
this input expression. And you went out to check
that this input explanation, because having the belly
button in on what does, does it mean?
Balanced parenthesis. Parenthesis means you can see
here opening curly braces, then opening round
record, closing down, and record closing
curly records. So all these are
called as parenthesis. So we have to see that
each of these parentheses, which is present in
this input expression, whether they are having
its corresponding here, this opening polymerases, whether it is having its
got his morning closing. Yes, you can see at
the end we're having this curly closing bend, as you can see here, we are having one of
the non brackets. So whether it is having
its corresponding clause, that is also called as right
pattern applause, right? Parenthesis, yes, it is
having the round Record, that is the closed round
bracket or you can see it is having close parenthesis. This is what we have to check. So here this is balanced. If I put something like
let me just open the door, this is the input expression. So here the same expression which I have taken
here week within each of these
parentheses article is opening his having the corresponding colleague
Louis parents. So if you are given
this expedition, say you are input
expression is this one. Whether this particular
input expression, you can check whether it is a balanced
parenthesis or not. You can tell me it
is not balanced because we are having here
opening Brown record, we are not having, it's got a spondee closed round bracket, that is this opening. Left parenthesis is not having. It's got as funding
round, right? At emphasis. As well
as we can see here, we're having this
curly braces close, but we are not having its
matching open megacities and this is not imbalanced. But this is what about
this expedition? If you are given with this, this expression is also not balanced
parenthesis because you can see here opening
it on record as having its got a spawning
closing parenthesis. But you can see the ear, we're having this
closing curly bracket, that is ischemia not having its goddess morning opening
curly braces and record this particular
expression is not balanced by not having
a balanced parenthesis. So this is how we will
distinguish actually. So we will ask user in our program to give the input
expression here and this, considering this
example to explain you, the diagram shows me we'll make our core
flexor relax the user. To give any input exploration. You'll see how to
do how to write the instructions for all of these requirements that we want the user to give
the input expression. And then we will
write our program and we can check whether there's been no expedition is having the balanced
parenthesis or not. What logic we should apply
your so let's see here. For instance, stack
is empty amino then we are having the thought, which is at a reference point because we will be performed
with the help of copy, will be able to perform which involved at the
top of the stack. So therefore, the top will be neutral equilibrium
minus one. When the stack is empty. This is stop using EDI. So this is the input expression. So for us what we will do, we even scan out of wall expression from
beginning to end. We reject. We will
check one by one. So we will simply
consider immunity can edit for this
input expedition. Eddie off character. So in that case, we will be taking a loop and we will be moving from
beginning to end. So one by one, we will first off all rehabilitate these
elements source. And you can see here the
0th element of this array, which is a character. It is having this
opening polymerases. So this is whenever
we are getting, we will make our logic, we write a logic when and
we're getting minima weekend. But opening curly
braces are opening round record are opening
back and record. These are all opening
bracket that is also the left call,
this left parenthesis. So whenever we are getting different parentheses but
an opening parenthesis. What I mean by opening, opening means this known
record can be opened. This curly braces is this dipole parenthesis
is opening curly braces. This typo emphasis is opening to co-vary
red square brackets. So whenever we get
these parenthesis, then we will simply
push it enough stack. We will maintain
the stack that is relevant in the stack
bought electing these areas of really maintain the stack in order to put all these
parenthesis, which I did. That is opening
parenthesis one by one. We will be scanning
from beginning of this, the Leanne and whenever
we aren't getting opening and we will
push it in stack. Once. This is one of the logic
which we will put. So why we are putting like this? Let me tell you. So see you, you can see here
initially we are having opening curly braces. What we're supposed to do, you simply push it. In fact, let me
modify the stack. This is what I have
modified when I get this opening curly braces. So I will make a logic whenever I get any
opening parenthesis, I will simply pushing the stack. So you can see initially
the stack was empty, sort of was minus
one. We know that. Then We are watching this. We want to push this
element that is opening braces because we have to make the logic whenever
we get an opening, parentheses are also called
as left parenthesis, then we have to simply
push it on the stack. So yes, we are at
the 0th element of this area of
characters will be here. The 0th element is curly braces. We are scanning from left,
from beginning to end. So we add at this position. So we got Collie
opening parenthesis, so we have to push it so we will simply implement
the top. By van. We have seen how the
element using MOS stack already we have
written the program and executed in audio session. I recommend, you could
recommend you to go through two sessions to understand how those stack using
that evokes upward. In that case, for push
operation, we want, which is going
opening curly braces, we will simply increment
both i months. So it was minus one becomes 0. Then this was eaten or at a given simply store this element that is
opening curly braces. Now next time when
we are at this next, notice we have scanned at
0th element of the array. Now next time, we are not bothering about pi
because we have to just check whether because
the stack we have to maintain for not
opening parenthesis. So now we blink again, we will not do anything
again, real disposition. Remember since we are
moving from left to right, that will be under
multiplication. So again, it is not, and it has nothing to do
with the parenthesis. So then again, one more
iteration will happen. That is, and we will be
at this opening bracket. You can see here this
opening round brackets. So what we're supposed
to do since Mia, our logic is never got any opening parenthesis me I said we had
indicated that it is, so don't record or whether
this curly braces, whether it has square brackets, we're simply put, we are supposed to push
it on the stack. So now how the stack
will be modified? I have modified my stack now on the top will be incremented
by one more position. Soon on top will
be equal to one. And now we will, we will be pushing this opening round racket and this tax on. You can see we are having
total two elements in the stack. This is how we loop proceeding. Next we will again scan. That is, we will move further. In the next iteration
we get 20 numbers, so it is not related
to parenthesis. Again. An exploration
will start again. We will be moving to next
element and it is plus. You can see her surplus is
also nothing to do with pen. This again will move
to the next weekend also when we have we're not
supposed to do with cool. Again, we move, we get
closing parenthesis, no logic we have to put, if we're getting any on
the closing parenthesis. So you can see it also
closing parenthesis. Parenthesis closing. So this will be the losing, this will be the closing
parenthesis opening bracket, opening curly braces. And the opening squared, sorry, what will be the
closing parenthesis? It will be closing,
a round bracket, closing braces and
losing squared. These are all closing
parenthesis. We've been checked. We'll put one more if
condition and logic. And we will see if
we are getting, we are getting from
this input expression, any of these closing
parenthesis. All struck while we have to check in that case that
whether the stack is empty. So here you can see we
stack is not empty, we are having some expression
then that is well and good. But if we aren't getting
any closing parenthesis, which is also called
as right, but, and this is, these
are also policies. This is the opening parenthesis, which are also called
as an emphasis. Whenever we get any closer
closing parenthesis are all right. This is our role is to see
whether the stack is empty. If the stack is empty, that means you can understand that. Amino let me, I'm
maintaining the stack for storing the
left parenthesis. But if the stack is
implemented in a vet scenario, if condition that MES
seeing this tech is North empty but it's
considered if the stack is empty and you
aren't having any, you bought any
right parenthesis, it is closing parenthesis
in that case, you can understand
that we are having, we either have a right
parenthesis autumn water than that of the left hand. And this is because the stack is empty bed and he wasn't me. I'm in cleaning the
left parenthesis under non left parenthesis. There it is, opening
parenthesis, but we got right parenthesis. If there is some expression. In that case, we will
simply say that he has an expression is not having the Melians parenthesis
because right, parenthesis or more than that. So in this scenario actually because suppose via having
the expression state like this is six
plus. And this one. You can see here that
we're not having me. This is the input expression. Then when we scan
from beginning, didn't we get disclosing
round brackets closing parenthesis and then B at what we have to check, you
have to put condition, but if the stack is empty, and then you can see here, in that case, we will
put the message. This is also called list, right? Parenthesis are
closing parentheses. It is more than debt of millet. You can see there is no lipid
and disease, so therefore, this particular
expression is not having a balance parenthesis.
This is the scenario. We have to also check that. But in that scenario, what is this situation be gone, this opening, round brackets that is also called
instead right? At anthesis opening and closing condition we are getting this closing
round bracket, which is also called
as bread increases. In that case, we have to pop.
The stack is empty or not. Stack is not empty of
busy because we have put all his opening parenthesis
on depth will be, will pop up from the stack. You know that dependent
I'm gonna be called upon to not pass and we
cannot pass any element. By default, the last
element which was, which will be formed
very top is pointing. So top is pointing
to the last element. So therefore, opening
parenthesis will be. What is this situation
in that case? You can see here that
Let's pick this node. But you can see here,
we are at this point. So this is that we got this. Whenever you're scanning,
we got this parenthesis. This is called, let's
say closing parenthesis, middle, name it like
this, and output. We can also name a button that says any
name we can give that. We should able to
understand what is the purpose of this
spread emphasis, this parenthesis, what
we are having here, when we're scanning, we are
getting this round brackets. So this is the round bracket
which we are getting. We will write a
complete program. Don't worry about that, just
to explain you writing. So whenever we get this, we had the first thing
is that we have to check whether the
stack is empty or not. You can see now the
stack is not empty, so we as opposed to four. So when we pop them,
what will be bobbing? That case, this
opening round bracket will be formed and
we will collect it and you'll collect
it in the variable. Let me, here we will
collect in the open. This is meaning that
we live in like this, or we can name this is m, this naming on with
Alonzo clear parenthesis. What other names for that? We get when we bought
what we get, we get one. We've popped from the stack. We will get this
opening round bracket. Let me modify the stack. So this will be the stack
that is the opening them. Round record is Bob
the ectomy and we have elected it and
we say opening, but this is what we
are getting this. So you can see dog-gone
decremented by one and this referring to this
previous element which is there in the stack
that is opening and residual. Now, let me recollect
we are having this particular
closing round bracket and we are having this
opening round bracket. Now we will, what we will
do, we will put the logic. You write some function, one function that didn't
mean that these two inputs, one in progress, this
closing parenthesis. And I let him put best opening parenthesis
and we will write, will pass these two
inputs to one function, which we will call it as much
but indices and which Mill, what we, what is the
focus on gratitude? Check whether these two inputs, whether it will
check whether this particular is having
the corresponding, it is, it will check whether
this is having its got a spondee opening parenthesis. We will have different scenario
because we will have for this round bracket.
Check on that. Even we will check for
the squared record after the opening squared record is
having its got his funding. Closing square
bracket rather than opening curly bracket is
having its got his funny, closing curly braces
are on the end. If it is having, then
it will return true. It will return one. If it is not having, then
we'll return 0. That is false. So that means it is
mismatch and we will give the message gender
expression is not having balanced because this is
what we have to check that we are having whatever
we are hoping we are getting. It's a spawning. We're storing. First of all, the scanning is this one. So it should have, it's got
a spondee and emphasis. So there it is though, a
software program right? Now, this is how we proceed. So you can understand
many bonds, these two inputs and
we put in the function and Matt will see what is
the logic in our program. Once we rank the
programming code block ID, then it will return one because it says it's
got a spawning this, you can see here in this
opening parenthesis as Hamming code is
forming closing, so this will not, and
therefore it will return one. Therefore, we, we
got the message, yes, it is having violence. Now we're still not done
completing the whole expression. We are left with an adult. I didn't meant to be scanned. In the next case, what will be scanned
actually now what we are appending with me
or friending with, and he was healed and
we appending with this last element of the array and that is the
closing curly braces. So when, so again, just moving to the Viagra. Yeah, definitely. You can see here this closing curly braces we are left with. So we add at this point
in the next iteration. So now again be gone. Losing. Recognize what is
what logic me and upright minute when we get to closing curly bracket or blue and
the closing parenthesis, which is also called
as right parenthesis, then we have to simply see Foster called the
stack is empty or not. So in our case the
stack is not empty. Then if not empty, then
we have performed. Then we pop the value
which we get factoring. We will be collecting it in this medium like this
opening fed into two. So let me modify this FAQ posts. This is my modified stack. That is we have for this opening curly braces and now
disability modified to this. We have an endoskeleton
was this one. We add a disposition
that is mirror the last element of
this expression. We are at this aluminum. So therefore we know
that this one is not, I'm losing the reason this
is not going to be gone, this closing parenthesis,
then we fall from the stack. What we collected it
in this variable. And so this is the bulb
demand that is opening, opening curly
braces, and this is the closing curly braces
which we reviewed. Beyond scanning, we
added this element, yes. So now we will put, we'll
call the function mat and pass these element
and this element. And we will check whether these are having it's good as bonding. But in this method, this
opening parenthesis as having a spondee closing parenthesis
in our condition, yes, it doesn't have any
depth would be written one, the match function
and return one. And level will display messages. It is not balanced parenthesis
and then we would see spill any element we got
left with food scandal. Now we have scanned the
complete expressions. And what last task
B as opposed to do, we are supposed to take. Our stack is empty or not because here you can see
since this is our balance, so it was staggering on VMT. But walk about the scenario. In that case when
the stack is empty, when we are done with scanning the whole expression
than the stack is empty, we check that yes, if
is empty then it will, we will finally displayed. We will return from
that function. We would simply say, Yes, this is expression completely is having balance parenthesis. But this does stack
is not empty, so handbill the stack will
not be empty. Index position. So it wouldn't be having
this expression C. Having this explanation save. Then this is an expression. In this case, you
can see here when we scan this list as
input an expression, this, I'm just giving you an example when the
statement on BMP. So when we scan
from the beginning, we've got to get
this. We get this. First of all, is the
opening iran brackets. So we watched it on the stack next time when we
scan other element, then we get this second
opening round bracket or unique portrait
on this thing. And we get n, not bother
then plus then 20. Then finally we get this closing parenthesis we're
supposed to call mistake. Mistake is empty,
no stack is not empty, so that is available. Then we will, once we
bought what we will get this opening bracket. So we will call
the match function yes, it is having balance. Finally again, we will
see that we reach to the end of the expression nothing better, but
still in the stack. Opening parenthesis
we are left with. So then we can understand, yes, Nortel, balanced
parenthesis because we left parenthesis
or more than that. This is how we will verify the input expression
that it is having a balance but emphasis on North, I hope so you bought
this complete naughty before
writing the pro-Nazi. Let's come to the
code block ID and let's write. Let's
see the logic. I will explain you
line-by-line this we are writing in C plus plus
and it will be executing. So this is my main function. Many new law supports to create a project in
the code block ID, you need to install the board
blog ID display available, very easy to install and
just write the program. And then you create a
project for C plus plus. And you include
this header files. I mean function by iostream because I have
an input and output. Then C string because
I haven't used some function which
is related to string. Let's see, man, we
will use that and this namespace that isn't
using namespace, std. Now I'm defining an extra 20. You know that in case
of stack using edit, that doesn't mean I'm creating
this tech static Navy have full size is fixed. We cannot change the signs, so we have to give this size on this statement we created at
the initial of the program. The program is executed. We cannot change the size
because I use is fixed. But there is a reason I'm giving the seismic and anything
hash define an extra 20. And you can see
I'm communicating. This is the stack which
I'm creating using EDI. So how to create? Since these are all the stack, we will maintain the opening
parenthesis and give n that will have on the
parenthesis that is opening. So creating the
era of the record. And I'm giving the size that
is here is defined as 20. You can give any sites depending
upon the otic Wyman and the necessary things
for the stack Mino talk biotic wired in Italy, the stack is empty, so we'll initialize to
optimally minus one. Then let's go to the main function and
let's start from there. And the main function
is supposed to follow the entry point to start an
execution of your program. So whenever you execute your
program and roll thumbs, this main function,
nine by nine, these instructions will
be executed sequentially. What I'm doing in
my main function, I'm declaring one Eddie, that is all the data
type character. All elements will be of
data type character. I'm picking this, this is
what input expression. So in this Eddy, I will take the input expression
and ask first of all, the user to give the
input expression and collected in this edit. Let's see how to use it. Video we'll be, we'll see how to make he was offered balanced. So this is just a display
message on the console. We UCL in case of t plus
plus as Howard the default, if you are writing those
same program in C code. And then input and
output support imprinting on the console. You don't use SEO, you
use the print function. That's only the
difference of wool, then you can simply copy paste if you are
writing and C language, just make sure Amanda, you on using CL, your sprint
depth and whenever you use, CAN use scanf and once with the header files which
are there and you create a project
policy approved, see project Nazi placements and you have to include instead
of these header finally, you have to include
stdio.h and Europe to include the necessary how
to find a string voltage. This namespace std is
not required if you write the programming language. So this is just am just mentioning you if
you want writing before moving to
the same values. Yes. This is a display program to check whether
balanced parenthesis. Now, one more display that is the entire
expression and guinea parenthesis all
what I am getting this message so that he was
able to understand yes, uses opposed to enter
the expedition. Therefore, the CEO and then
user will get an expression which I have called
this function that is, so you can see I'm making
the use of string. It is, is the function button. We will ask user to give the input and get their input on the unsold
that will be a string. So therefore we are
using get SS for string and this EIN an XPS. So I told you this
year we'll collect the expression,
input expression. So we collected in the
string by the name, which is a character array. So this is an input expert in intellectual
exploration that is, in our case, this
ion expression. The user give this
whole expression, we will collect them
that Eddie off, Correct? No. Then I'm calling this
function check bed and this is all what this tech
bed emphasis do. Foster quantity in
this check parenthesis being positive input expression. You can see and you can
understand what we will do. We have already discussed
mucin that given a different, different logic, if we
get any left parenthesis, then we are simply
SF wants to push it on the stack device it began to write parenthesis we as opposed to check if
the stack is empty, then we will say right
parenthesis are more than the left parenthesis
status stack is not empty. Then we will see
when popped from the stack and we will
simply pass it in one mode, functions a match, and we will see it as having its got
a spawning parenthesis. So let's first move on to
this function and see why. Return visitor Tony. Yeah, collecting the return
value in this video, but in orders is balanced. This is not an integer
types of discipline. This return me Yvonne. A dysfunction in return. I know uneven and that
it is a balanced. So this is the reason I'm collecting here so that
later on I'll make use software will
just display whether the complete explanation
is bent into the narco. Move on to detect. We'll
move what we will see. What is their definition
of this check at anthesis when we're passing this
whole input expression. You can see here this is
the complete function. Object parenthesis here. This is the whole function. So let's see what
we are doing here. So here we'll have, we'll have the return type one since I've worked
with Ribbon 10. And the input will be in
preventing human sad Adi, which we are passing
the input expert. In fact, we are putting, notice the whole expression that is this exponential
we are passing. Now. What we are doing, we
are taking a for-loop. Why I'm taking this Guadalupe? Because you know that
we are supposed to scan from this beginning of this exploration,
that is from this. And that is a reason
maybe required upon loop. For loop int I is equal to 0 I less than spring length
of this input expression. So how much time the iteration should
happen and at the end of the string so that hold
this I will start from 0 until n. We want to
rotate and then I plus, plus this inner for loop. Then we had, I think
that logic that is one-by-one each element we've already tell him and he will change these conditions. Notice even check this
expression subscript I is equal, equal to this logic is what it is done logic
or to check it, we are getting element as
our opening parenthesis on. So quality is a
left parenthesis. So you can see I've
put this event, you do EXP and this
is the subscript I. So here I initially will be 0. So therefore, what will be here? It will be this
opening curly braces. So we have a deck. What each element we'd have to check all these things if we get any opening curly of racism, if we get this
opening round bracket of Rigoletto opening
grand record and what we as opposed to do, we're seeing me as
opposed to simply watch it in this stack which
which I have for you, that is the purpose
of the staff to store opening parenthesis
or left parenthesis. So we are simply calling
which function on the stack since Vietnam
blimp using the stack here. And we're passing
this opening that is EXP S subscript guys want
subsidize, want to detail. In every XPS, subsequent
0 will give you the opening parenthesis
I'm passing in. I'll call the push function and simply pass this
opening curly brackets. So what you want, it'll ask is to push this guy opening curly
braces and the stack. So let's see the logic for that. We know that it's
a simple audit. Me have already seen
in our earlier session for the stack which
involves using an EDI. So this is assistance or why
I am taking input or human because I'm passing opening curly bracket because
our character, so I'll select in
disconnect this and that. First of all, before watching any element in
manual using an EDI, we have to always check my than your stack is full or not. Second spoiling, you
are not supposed to push my stack or
whatever and ago, so this is a definition. What is the definition
of stack will be known. This is my Instead. If this is if top
is max minus one, we have seen that
whenever there is a reference to the element
which is the last element, which is simply the
index is like this. We have defined already
the size of the stack. And if we add at that size, that is the last maximum size, that means the stack is
nothing we can poach already been written by
an impact is indicated. If the stack is not
political returns 0. This is, we have to check men, it will be called me an MMU, Bush before pushing any element. In our case, the
segment on people. Because the earlier
at the starting, starting it is now
then what I'm doing, I will check on this tax. So what does the logic work watching we have to
force implemented top. So here I have written this
the same logic in one line. It says, so i'm I'm using the agreement to lipo
postdoc will be incremented and then the stack underscore left parenthesis subscript will be implemented from minus one to 0 because it will be
incremented by one. In Italy, stack is empty, so women may agreement
thought becomes 0 minus one mutually definitely get stuck under school penances. This is subscript 0 is equal
to this value or table users by alphas in equilibrium. Finally, in our
stack we go on to opening curly bracket pushed. This is dumb thing which
we are doing here, then moving and the next, this check bed enthusiasm. Then this is awesome. I'm just
matching the dog scenario and logic to check whether an element is having is Zope link button
business logic one. So we have to put
because different logic and we can also get the
closing parenthesis. So this node, this
if condition I put another loop itself. You can see that if this input Alignment is the closing
curly braces auditors. You can see I'm using
the auto period of you because it can
be anything audited every result opening or if it is a closing bracket or if it is often losing
squared record. And you can see here how
we are checking closing curly braces or losing ground bracket of using
square record in that case, what logic we have to do, we have seen that
whenever we get the closing parenthesis or we
can say right parenthesis, we are simply supposed to check, post very posting the
stack is empty or not. If the stack is
empty, you can see in that gives me will
flip a message, right parenthesis more
than their parenthesis, this message given game. And then we will return 0 on. But if this stack is not
empty valence, good, that gives me will simply pop from the stack and
we will collect in the variability that is left parenthesis on which is also called list,
which is returned. You can also name it as
opening parenthesis. So you can see why via hoping. So first of all, before we
get started in this video, but is that correct or no? As I told you, we will call
my function and we'll ask this left parenthesis that is
opening curly bracket here. And what does this
expression subscript i, it is Mozi, it is simply as S2. See how so then what
we will do here, left parenthesis needed Bob. So whenever we are having
me economy in the case, actually when you want to
get the closing parenthesis. So first off one, in our
scenario you can see that in each element that
is opening curly bracket, we didn't got any
closing parenthesis. So this condition, first of all, in our case will
not be satisfied. We will read this condition
will only be satisfied because we got this
opening curly brace, curly braces, and we have
pushed it on the stack. But this condition will not
be satisfied since it didn't. We already heard this
conditions are despite. So therefore, this
is just to explain. You will not even put different, different conditions
for each element. Then it is closing parenthesis. Then we have to simply check
whether the stack is empty. The stack is not empty. Well and good. Then we will pop from the stack will be
stored in this variable, and we will pass this
left parenthesis and this left parenthesis
will be cut as will be the parenthesis which we are pumping from stack. And this scan parenthesis,
which will be there. What we get as a
closing parenthesis. That would of the things
we will be asking to this mass function and what we will be doing
in the match function, as I thought UV will be simply. This is a match function
which is done in vitro. You can seek the area having to input that
humans left and right. So here we are checking if
the left parenthesis is, This'll opening curly
bracket braces and we are using angle for either
because then we know manuals, me it was an operator lender to off the condition
should be true, then only it will return true either or it will return false. If my knob, the
condition is false, it will return false both and each endpoint it
will return false. It will return true. This one condition, and if this other condition,
both of them are true. These things, we are
checking whether this parenthesis as having its
beta's forming identities, then it will return one else-if, if it is having this opening is having its got his
funding close, if this opening
squared is having corresponding R-squared
record, then return one. Otherwise, if no, none of
these, then it will return 0. In our case, this
condition is not satisfied because we are opening at the very beginning of the
expression and we got the opening curly braces which we have pushed
on the stack. Then this is what the logic we have two active I didn't want will be the scenario again. Scanned and excelling meant that despite so we have
to not bother. The next will be multiplication,
not while the, again, we had this opening
it on brackets. So we will simply, this
condition will be satisfied. That is, you can see this first condition,
that is this one, because we are using a
court operate in order to operate them enemy use
any of them is true. The world decided
will be it through. So therefore this is
true in that case, so we will simply
push it into stack. So in the stack you
can see me half cost curly braces opening stored. And the next we have stored
this opening bracket. So we are having two elements to totally top is pointing
to this last one. Now, this condition will not be satisfied because we go
into opening bracket. So therefore, again,
next iteration, what will happen to get 20? Then we get less
than, we get four. We are not bothering about that. Again, we are getting, we
are getting though laws, bed and thesis that is
also for this, right? Then finally, what we are, what logic this condition
will not satisfy. This condition
will be satisfied. This condition
will be satisfied. Therefore, because this
particular thing is turning true. Therefore, condition will
be true. In that case. That, that is,
since we are here, therefore we live simply
pop from the stack. So when we pop from the stack, so fast upon me I protect causes the stack
is empty or not. So in our case, yes, the stack is a stack is not empty because we haven't
put any men's prison. And the last element
we are having this opening round brackets so that whole stack
is not empty. This foundation is
not doing our case. In Xcode, we will be simply
poking from the stack and we will be collecting in the variable thickness
left parenthesis. What we have heard
in communicating the opening round brackets or openly and following
the match function we're passing this
opening round, recognize his name is emphasis as well as me or
passing this scan. So what we are scanning, scanning this clo
5. Infix to Postfix Conversion & Evaluation of Postfix C & C++ 1stHalf Session4: Hi, new session. I think the program
and executing it in Windows infix to
postfix conversion. Evaluation of the postfix
expression which we obtain after converting
infix to postfix the same. We will be evaluating it
in C and C plus plus. In earlier sessions, a veteran in the
earlier two sessions, I have covered what infix
to postfix expression. We have seen that. And we have also seen how to evaluate that is
postfix expression, which we have explained that
the same on the whiteboard, I will be taking the same piece, same program which I'll
explain in the whiteboard. I will be, I think
I will be executing it in the code block and we
will be seeing its output. So this wouldn't be a
good practice for you, so that you can simply copy, paste the whole program in the code block ID and
windows and executed. So we'll be seeing it
in C and C plus plus. In this manner,
you will be having the hands-on to already the concepts may have seen in the previous session
on the whiteboard. Let's write the same code in
a code block and executed. We will be taking
this expression that is the index exploration. You have already seen what
is in fixed expression. You can see here the
infix expression just to quickly revise in which the operators
you can see here plus minus all these
other operators. This is present in
between operands. In fixed, that means the op, depending upon the
position on top later if they decide what
will be the expression. So why this is called
as in fixed expenses. Imagine the reason this operator is present in between
the operands. So you can see here in-between Ethan for this class is present, in-between important with
this minus is present. So that is the
reason it's name is in fixed explanation, not heal. The same explanation. You'll be writing the code. We have already seen the code. I have explained you on the whiteboard in the
earlier session. In pickup, the same code
on the code block will be executing it in C and C plus plus when NBC
in both languages. So let's move on. Let's write a program
and executed in those using C and C plus plus. I'm just moving to the
moving to the code block. Phosphate will be seeing
the code C plus plus. This. Let me increase
the font size. This is technically I have
created in the code block ID, so we know that it is very easy to download and install
the code block IDE. So you can just refer the same. And you will have the ID wherein you can write the
program and executed. So this is the C plus
plus program for conversion of infix to
postfix and evaluation of it. I'll explain your line by line and you'll be executing it. I already, I have explained
you on the whiteboard, so I'll just quickly revise. I just wanted to show
you how does it execute. The same program which I have shown you on the whiteboard, has been an explanation
how we will do the same program exits be
executed on the code block. So we'll be also seeing it. I would put on the
code blocks or this is this will be in helping you to have the hands-on on the same program
and you can copy paste the same code
I have on school. And there'll be also I have
also shared the same code. You can simply copy, paste the same code, and execute it and see
what will be the output. The first list, let me
in the notepad just to quickly explain you what in fixed explanation we
will be taking here. Consider this in
fixed expression. You can see here this end fixed explanation we will be in. You can take any explanation. Yeah, I'm taking this
in fixed expression, this seven week on
voting in postfix. So first of all, you know that how does this in fixed expression should
be converted to fix. So as we know that
the parenthesis, first of all, fixed explanation, who pulls fixed, how
it will be fixed will be converted to the postfix.
So it will be scanned. It right like this. Starting from this. It will be, it will be scanning the expression from left
to right Foster point. What will be the
thing in this case? What is the purpose actually, using the stack in converting
the infix to postfix. We have already seen it that
we are using the stacks, but FECA and cheap purpose
because it will not take time. You don't need to
scan again and again. Expression we have seen
if you don't use stack, then you have to scan the whole expression from
left to right like this. You have to scan from
this, from this. If you don't use stack,
then you will be scanning from left to right and
you will be seeing, yes, this parenthesis
is present. So you know that parenthesis is having higher
priority than you will. And it should be evaluated
first and afterwards. Again, after the
evaluation on that again, they will be spanned
from left to right. Again, it will be checking
for next highest priority. So in this manner,
if you don't use stack in this minute
will be executed. So the reason why we are converting this
infix to postfix, and we're using the stack
because for a DC10 purpose, so by using this tag
you will have will be converting to the
postfix expression. We have already seen in
the previous session by what is the
fixed exploration? In the exploration in which the operator is present
after the operands. For example, if you
consider this exploration, that is eight plus four, this is an expression, so it's for fixed will be 84. And then, you know that
why we are converting this because in this manner in postfix explanation it
also remove the parenthesis. The parenthesis are removed, as well as the priorities are arranged in a sequence order. So that is a reason
you don't need to scan from left to
right again and again simply by von go from B to
convert infix to postfix. That result in
postfix expression will not have an instances. In digital operators will be
arranged in sequence order. So that is a reason actually we are converting to postfix and that can be possible
efficiently using the stack. So here we'll use the stack. So I've already explained all these concepts in
detail in previous session. I explained you on
the whiteboard. So here this means, this main purpose of this
session is to just show you same piece of code I've
written in the Windows. And we'll be executing what I have written in
C and C plus plus, you can simply copy, paste the same piece of
code and executed. So just to quickly
revise the concept, I mentioning it again, again for you friends. I hope you understood
what is the yield. Finally, we know what we're supposed to
do, what it will do. We have seen that the
stuff on this parenthesis, we know that what
will be the logic? First of all, we will
be scanning from a to B is the process by NB
scan from left to right. First of all, we are
using the stack. So what we will do, we will, we will simply store the operators whenever gonna be scanned from left to right. In this manner, we've
distorted the operator and we'll take one num eddie. That name will be the
boats fixed at it. We have seen that. And we, we will be taking a stack. So we have seen waterfall
input required in order to convert this infix
to postfix one is required. Which name will be
the pole speak, Sadie and one stack
using the EDI, we are using the index. We will be storing operators. We have seen things are
required and previous session. So first of all, we'll
scan from left to right, and then we convert
infix to postfix. As we find operator, we will store in certain
array that is a false fixed. Then we scan the next symbol. That symbol is plus. When we find the operator, we will simply push
it onto the stack. We have seen that again, the operator comes for Rivest will simply store
it in the area. Again, the next operator
comes to what is it? We have seen what rules we should follow when we
convert infix to postfix. First of all, these
adults symbols, these each symbols which comes. First of all, please
keep into mind that whenever you
operate your CMS, you as opposed to store it
in the postfix setting when it comes to you as opposed to store it in
the postfix setting. But when the operator's comes, you have to deal it with
best stack using the array. So first of all, you have to spend never
looked at this is the same scan symbol and
you have to already, we have seen all the
conversion rules. So once you get the
symbol is suppose plus. Your stack is
initially it is empty, so you will simply push
it onto the stack. And other symbol comes.
This is an operand. This you have simply storing, added again another operator. And say, this is
a scan symbolic, that is this minus
if it is priority, if it is lesser, as compared to that of
the top of the stack. In the stack you're storing
if there are some operators. And you know that what is the top of the stack
validity reason. Decent element is your
top of the stack. Obviously in this tag we're
storing the operators, so decoded top of
the stack will be operator in the priority of this fence in
ball, this is a scan. These will be the
scan symbols and you compare it with the
top of the stack. If it's priorities less
than the top of the stack. And you will simply bark the top of the stack and
you will store it in. Eddie. You are suppose to
compare against the same scans involved with if you thought
I was scared Bob, the top of the stack element
of this type you will form, which is the topmost element of this technical and meet up. And it almost element
will be formed. Then the next step
it will be there thought will be the
other previous element. So again, you have to
compare these scans involve embedded some operators
left in the stack. Then you have to compare
with the other priority of that symbol with
that priority. Again, if it is a priority on this Canson ball is less
than alpha of the stack. Then again, you have to
follow up on this accident. They simply keep on pumping. You find this priority
of the scans symbol lesser than that of the top of the stack months you'll
find this top of this, this scans in bulk rarity greater than the
top of the stack. If it is like this, then you simply pushed
onto the stack. So we have already seen that
in our earlier session. If you find the priority
of the top of the stack. If you find the priority
of the scans symbol equal to the top of the stack and you have to check the associativity. Associativity on these operators
are from left to right. That is, you have to have
football up on his thing. But if it is right
to left and you have scanned symbol
onto the stack. So these are the rules
which we have already seen. Also I will be making, I will be also
mentioning these rules in some documents so that you can also it
for your purpose. I hope soon you got the point. So first of all, if this
symbol, these are the scan, this one is four minus, these are the scan expression. What I'm symbols will be the scan symbol comes
with operators. Then we have protect added emit back-up bus stack,
top of the stack. Quickly devising input. Symbol commodity is lesser than you have to pump
the top of the stack. This can symbol
priorities greater than. You have to push down symbol
onto the top of the stack. If it is equal, then you have
to check the associativity. I did if it is left to
right associativity. Again, then in that case you'll be popping the top of this tag. If it is right to left associated within
any good fortune. This is what the rules
you have to follow when you what infix to
postfix expression. So I hope you understood. This is just a quick revision
we have already seen in the previous two
sessions on the whiteboard. So the main purpose
of this session is to just execute the
same program AT, for you under the
code block IDE. So first of all, you
can see here this is the C plus plus program
and the same code. You will be finding it. I haven't given you. You can access it and you can copy paste the same
for your code. I've made you made it
available for you. First of all, in
C plus plus code, as we've seen the C plus plus, then we will see in the
C B also executing it. So you have to foster upon mentioned the header files
which are required. You can see here iostream
and Nortel string dot. All these header files are required because you
will iostream is for inputting and
outputting when you call the functions for the same. And these, I'm
defining these macros. So we will see when
I'm making use soap and stockholder
view here we are using stack using EDI. So notice the reason
this is used to define the size of the stack
so that this is fatigue. Because i'm, I'm using, I'm using a static array. We are using stack
using arrays is static. You cannot creating an empty. So therefore, I
haven't mentioned the size we have prevention does ice at the
compile time itself. This is a size which I am
giving full stack using Edit. You'll see how Nika you saw fit. In case of this C Plus Plus, if you aren't aware of It's
language you will write. You can write the same
code in C plus plus. You can understand it. If you want to read off see, I will show you how
to see also how to write for C plus plus. You know, we are creating, we have used up to us. And there are
different specifiers public, but I read all this. This is my class named
as infix to postfix. You can see here this
classes like this. This is my class
infix to postfix. And you can see here this is
oblique axis by a specifier. And you're a private
access specifier. So far, so far, in public access specifier,
you can see here, I'm creating the constructor which is public
in fixed reports, fixed construct, you know, in constructors initialize the video amendment
of getting uses. You can see a public I had made all the functions which I'll
be using in my program. I had made it as
public and I had made private for an all
member variables. You can see here we are
using stack using an array. So we are using the
top will be referring to the topmost element
on stack using EDI. And this is not Stack named
by elongating stack max. So this is the
stack that didn't. We will be storing OR operators. This, I'll let you know what
is the purpose of this. Extra things that is
whitespace. So what I use here in our class. We know that since we are
using stack, using Editor VR, we're supposed to know the operations related to
stack out of Fortune fall. Why does push and pop is used? We know that we will be
popping at some condition, may be pushing at
some conditions. What are the rules we
have already seen it. I will, I will show you how
to prevent even use this. And this function that
is in this function is flawed and working infix
to postfix explanation, since this program is for
conversion and to infix, to postfix as well
as the evaluation of the postfix I have on social and new on
the whiteboard, how to evaluate the
postfix expression. Therefore, this
function will be just converting in fixed
to false fixed, which I had to buy the
rules which I mentioned. And the another function, evaluation once we get the
full speaks explanation, dysfunction is used to evaluate the same
postfix expression. And then priority. This end disparity incoming by these two functions
are used because as because one function
will be called when dealing with the
left-to-right associativity. We know that bottom
left to right, left to right when associated with the comes into picture. And then vitae, your
priority of the scans in bold is cmd and same to that, all the priority of
the top of the stack. Then associativity comes in, index is in the associativity
is left or right. Then you will be popping
the topmost element of the stack and you
will be supporting in your result in
postfix expression. Associativity is right to left. In that case, you will
be pushing the scans in bone onto the
top of this stack. This is the thing, you know
what the in-depth case, the left or right associativity changes, then the rules changes. So therefore I have
created two functions. So one function name already another function for
anonymous but editing undisclosed incoming
symbol depending upon associativity, whether
it is left to right, I will let you know
how it is executed, is empty to check whether
your stack is empty or not. Since if your stack is
empty by this condition is required because you
aren't popping right? Whenever you fork, you have
to also make sure that some elements are present
on your staggered. Nothing is present
on your stack and sending us for being done. In that case, the
problem can come, come. So that is the reason
you have to check. But if your stack is empty, there is no question of hoping. So that is the purpose of it. Now, menu, so this is the, these are the functions which we have seen
water in our class. What member functions are used, what member variables or use. Now let us go to the
main function and then let us see how the
execution takes place. We know that in case
of the main function, the control comes in
the main function and line-by-line instructions
will be executed. So far as tough on
this control comes when you execute the
C plus plus code until all comes here in this main function and
line-by-line instructions. So here what I have done, you can see I had taken
an area of character Eddie for an infix
expression and corrected edit for
postfix expression. If I am taking the character
a report in fixed, we know that in fixed
explanation will be simply this one
which I've shown you. This whole exploration. I'm taking this up. This is my fixed explanation
and the resulting, when I do the
resulting expression which I should get is
a postfix explanation. So that should be also an ID. That is the reason
I've taken them at ease minus the input expression
and the result in which we'll be getting after I
Security in this code will be the postfix so that it
doesn't result in the area. Now this is just a cout. We know that in C plus
plus C out is to display on the MSc infix to postfix and evaluation
on the postfix. This message is just to
display on the console. This message will be
displayed so we use c out. There is a reason
we have included the header file hash
include iostream. Then I'm using long int Val. The top I'm using, I'm initializing my
top four minus one. We know that initially the
office and the stack is empty, so therefore it will be
minus one. The opposite. Bill in the mandible,
you will start filling your stack using edit and your talk will
be incrementing. We will be seeing that so far. Stopwatch alarm, this
message will be there. So this is all explanation I have already explained
you on the whiteboard. This is just, I quickly move
actually and executed fast. So first of all, this
message enter that in fixed explanation so that when I'm using this
function getters, getters, this new school in the
input from the user on the console so that you can give the input in fixed
expression like this. You can give this
expression here in your console and
you execute the code. And then what I'm doing is I'm creating an
object of this class. So this in fixed reports fixes the same class which
I have shown you now. You can see here this class is by the name and fixed
to force fixed overhead. And I have already given the construct the
member variable, right? You can see here I'm
creating the object of the same class by the
name into forced by this. This is a static
object creation. That code, I'm not, I'm not
doing the dynamic relation. You can see here this
is a static object. So by this object, I'm calling the function that is
infix to postfix. And I'm passing this infix and postfix in fixes more
infix expression. First of all, it is the
expression which I am giving you, the one, whatever you give
them fixed expedition, you are sending that and you are giving sending the
postfix expression in Italy discourse fixed
explanation is having nothing by this function. Whenever dysfunction
via we'll be putting the logic in it with
a postfix expression. So VS simply passing nothing we are passing in its
postfix in fixes them. Input exploration which you
are taking from the user. And this force will
be nothing initially. Dysfunction. We'll do the load logic, we will do the logic and
dysfunction in order to convert this in fixed reports and we'll fill in this function. It says, let's move on to this function and see what
will be the definition of it. This function that is in fixed
supports fixed function. You can see here in
this function in fixed, false fixed, you are
passing this month string and then you are
passing another string here. In this exploration, in this string poster hall in this function, whose
strings are there, this will be your input in
fixed explanation and this will be initially no
stealing anything. But in that logic
we will keep on storing and not
postfix expression. That by Ethan wanting to
the infix to postfix. Let's see how far I stop
on in this function. You can see I've
declared initially the variables we receive is the use of each video,
but this one by 1. First of all, you can see
I'm using a for-loop here. I've already explained you
on the whiteboard via, via using a for-loop
because we will be scanning from left to right. First of all, this is fixed. Exploration is stored
in the activity, so v will be one by one to
each symbol is weekend. Compare actually with the rules, if it is an operand, we will be simply storing
in the postfix expression. If it is an operator, we
will be dealing with in this stack that we
have already seen. So therefore, we are
using a for loop. So all these non-peak
I've already explained you in the
earlier session. This is just to show you how we do it and we will
see the output. I'll just quickly revise. So therefore, this
for-loop we are using for the same string length
in fixed explanation, one by one if VS scanning and this infix I,
collecting and symbol. And therefore, we are
using this switch case here because we will probably will compare
with each routes. So first of all, why I am using this condition for using
this whole switch cases, for such cases written
in if condition. What does this condition? It is not about
whitespace symbol. So therefore, you know that this is the symbol plus is the same on all these other
symbols. We are checking. This should not be
the whitespace. So since we have
our main concern is to deal with the operands and
to deal with the operators. And if, suppose that he was
going like this, like this. So first aid comes
then you can see there is a space, right? There is a space. So we have to ignore the space.
We don't need to. We are not having any
loop all of this space, so we have to ignore
this and then we have priest scandal,
a bit operator. So for that purpose, this whitespace
function is used. So if you see here
in this whitespace, what I'm doing here, let me, this is simple, I'm
checking for this. You can see I'm created
this Brightspace in which if it is a space
that will be like this, I'm checking if it is
a blind audit because I had if it is a blank one time, then it will return one. That means there
is a whitespace, so we have to ignore it
because we don't need to scan. They didn't know what
that network I'm writing the switch case in that
whitespace. I'm taking. If it is not whitespace, then only we are uncertain
protect with the rules. Otherwise, we have been not going to ignore it
because our space, we don't ignore it, proceed with other symbols. So that is a reason
this condition instead, I won't tell you
under responsive know this whole concept, not switch cases that are in it. And so, you know, whenever
we get company parenthesis, we as opposed to a pool
check on the best path. Then wherever it is a closing
parenthesis via fault, all the elements from the stack, they'll find actually the opening parenthesis
on this logic. We have seen the same thing, the coding I have written, so I've written the
book and you can see on my one thing that is, if we find this, then
one-by-one bumping must be at checking if it is opening and we have
to stop pumping. If it is not opening,
then we have **** off. And this we will be storing the result in
postfix expression. This logic we have already seen Na plus minus multiplication, division mod operator so far. All of these, we're not giving
break, that means this, you can see this logic
will be there for all these operators
wherein there is no break. You can see this
logic is for the same whenever you come
with the operators. Now you can see I'm taking
with what I'm doing here. I'm checking. First
of all, first of all, I'm seeing that men have and I'm getting
any scans symbols. So if my scam
symbol is this one, gap, if it is plus, if it is division like this, if it is like all these operators that these
are the scans and bolts. So first of all, I
have to check these. Can I get any scans symbolic projected with buffer edit
you off the top of this text. Before checking the priority
of the top of the stack, we're pulling this check whether they are stack is empty or not. There is no operator president, there is no question to check. This condition is
must you have to check whether the
stack is empty or not? If it is not empty,
valence would then only you can check the
polarity of this text. So you can see here
I have checked, but I didn't feel good stack
view on this Canson ball, if it is lesser or equal to
that of the top of the stack. In that case, you can
see here, I'm simply.
6. Infix to Postfix Conversion & Evaluation of Postfix C & C++ Session5: Fraud before these
operators that it's four plus minus multiplication,
division mode ratio. You can see I have
not written directly. This instructions
may have written. So on this instruction
which is there, will be executed, will break, will be executed
for the same event. And bird, it's embolus
plus or minus on it. Itching, division mod reach
to support all of these cases wherein we have not given the same instructions
will be executed. The instruction that is this, what we're supposed to do? So whenever the scans in bold is plus minus
multiplication division modern raised to the
same instructions will be executed since
we have not given brake. And what is that instruction? First of all, we know that
whenever the operator comes, we have to check did not rule. That is we have to
change the priority of the scans involved with the priority of the
top of the stack. That hole. Once this operator comes, that is, is our exploration
in flux expression. So whenever we get the operator notice plants or it begins minus bigotry is true, then these other
post-op follow me, know that the school in
Victor expedition in which, in which a business in bulk glasses are
symbolic for deserts and minuses inborn and
so on until the end. So if it is an operand, we know what we're
supposed to do, reassembly supposed to sort
it and was fixed at a, which means we have created. But when we get the
operators like plus, minus, minus Audre student, we have
to deal with the stack, we have to operate with the
stack and we have to check the priority of
this scan symbols that is this with that
of the top of them. So this is what we have done. Now as you as I told you, that the priority of
the scans and voltage, if it is plus this
is a scan symbol. At this point. If he added which point under scan symbol, you
can see the split. If the scans and ballplayer
D is lesser than that of the top of this
stack and the top of the stack, whatever
operators present. If there is a reality
of this camps and molecules lesser than that
of a bit of a mistake. In that case, we are supposed to fall off the top of
the stack and we have to support distorted and holds fit expedition
that sports picked. If it is illustrator, if this scans and bold clarity, if it is greater than that of the priority of the
top of the stack. In that case, we have simply PET scans and ball
onto the top of this stack. I hope so you got, but
if the priority of this scan symbolic it is less, it is equal to if the priority of the
scans and monitor is equal to that of the top
priority of the top of stack. In that case, you'd have
to take the associativity, that is a fetus left or
right associativity. And you have put simply pop the top of the
stack and store it in quotes fixed expression if it is right to left
associativity in that case here for some people to discuss involved in onto the
top of the stack. I hope so you got,
that is a reason. You can see here, I have written this thing that
this condition or this condition is for
associativity right to left that is radically of the
scans involved with one. If it is equal to net of whatever scans and bold comes
and if it is an operator, then you have to check
with the priority. So if the participant equal to that of the top of
the top of the stack, and we have to check
for the associativity. So we know that as I have
discussed on the whiteboard, that get if you're having
plus Audit be having minus. In this case, you can
see first of all, this flux N minus
the default lesson, minus these blue dots on
them or having them seem. If this is your scans
and this is the top of the stack in that gives
me object the priority. So if you know that in this
case the priority on both of these operators or to embed
CPP file mode on them. You know that if
it is like this, leads to reach to this, we get this Canson
bolus raise two. And if we get the top of
the stack as raised two, then we know that vote on them. First of all, they are
having the same priority. Then we have to deal
with associativity. Associativity is what I mean if I say the associativity
is right to left. So suppose you can see here, this explanation is
there. You can see here. In that case, associativity in the sense suppose I'm having, suppose I'm having
this expedition, see this one. It is. It, suppose I'm having, this is your expression
and fixed expression. You can see here. Suppose
in your stack you are having raised to and
in your yard rhos cancel your scans embolus
restore annual stack is also having thus top of the stack
is raised to in that case, how, what the associativity, how it will be walking, it will be first of all, both of them are having same strategy because
their siem operator. So that equal with an entity or equal to that associated
with this dipole. Let admins execution will take from right to left like this. So first, do wrist or false, it will be two raise to
three will be executed. You know that two raise to
three is will be eight. Then what, whatever
desert we get from the students to
treat than it is in. So then what thumbtack
three, then two, raise to k. This is
how it will evolve. So first, what we'll do, what will be this will be evaluated at is
to restrict tree. Suppose we get two
raised to three. Then finally, this food is
still eight will be executed. This is how it works. So definitely associated
with these right and left. In case of the plus minus, the explanation is laying
this minus two in this case. So in this expression so far, so follow me know in the
top of the stack is top of the stack is you are saying the US and your scan
demolish minus. In that case the
specific gravity of this plus and minus
I've seen right? Associativity, we know it. Plus and minuses
this left to right, that expression first eight
plus 40 will be evaluated. That is, it will be it, let's fold will be 12. Then this expression is
eight plus four is 1212, minus two is minus two, so it will result to it. This is what the
split takes place. So this is how it was so this is what I have
written in the fall. Also know that dismissed thumbs interpreted and we have to consider the
associated 3Ps rank. Or else what other operators which we have taken in our code by associativity
is left to right. Therefore, I have
in this condition or that condition on
you have checked here. I'm checking that the
stack on top of the stack, if it is having this operator, it is, that's three, it's two. And if this involved
scans and roll is also these two, that is, you can see a bulldog demo
damage to in that case. We know that the index
is the situation. And because we have
to simply what we're supposed to do since I
told you that in case of this FBI having the
same operators, then having no identity on top of the stack and
it's going to involve same. Then we're protect
with associative, associative entity
associated with these right-to-left than
what we are supposed to do. We are not supposed
to pop your support. It'll push deeper
what I have done. In that case, m equal to our left to right are
associated to repeat it. This is a different
meaning. We are, we are having the same priority per top of the stack
and scan on the symbol. If the associativity is left to right and
we have to Paul, but if necessary, abilities, right, for lambda and
we have to poach. Therefore, I have created
a different function that this priority incoming symbol. So in this gravity
incoming symbol, what I will do Post.all sinter and supports to
push me know that it is associated with these regular Piazza
posts to porch. That will what I will
do for pushing purpose. I had created a separate
function that is disparity, this attack in this one that has polarity underscored
incoming symbol. And if the parity of
the incoming symbol, if it is, then that dog, dog priority of the top of the stack. So
what does it mean? So Falstaff on what I'm doing, since I'm, I'm supposed to. Which this symbol
which began that is, if the top of the
stack you are having as raise two and this incoming
symbol, that is this one. If it is all of
its wonders onto, but it's still having this one. This imbalance on the stool. In this case actually
what I will do, I will use variety of incoming
symbol. I will return. The return value is compared to that of but I did you of this
tack on the top, what does it mean to quadrapole? We know that though. Let me come here
in this expression as I thought you
epidemic students to do. In that case, suppose I
am having stack is one. Stood as well as my scan symbol. Is also the symbol
that is scandalous. This, these are the symbols, the operators which are here and then fix
exponentially symbol. And we know that the
top of the stack, what is the top of the stack? So it both of them are equal. What I will do, since
I'm supposed to be no, the associativity for this
is that we're supposed to, which the scan tin want
onto the top of the stack. So that will whatever you do, I will simply have created
a separate function that is the same Sima
operators or that I cannot call the same function
that is the priority. So you can see here In disparity function
what we are doing. Let me show you the
function then even understand this
priority function. The function, why
I'm using this, this is a class name
scope resolution. And because I had
created this function, remember, I have defined
it outside the class. They put on using this
gleam of the class. And then the scope resolution. This one, the name of the
name of the function. So what I'm doing,
if the priority, these other ones, these
other characters. So if the priorities, that amount of time returning
0 evidence opening, if it is plus and minus, we are not using anything here. So I'm returning. Since we, I'm returning at some, some positions are
not using break. Since four plus n minus, you can see partners we
have not using break. The biggest note that
this will be executed, the same instruction
will be executed. So both plus and minus,
we are returning. One. If we are having the scans
and boldness plus and OH minus will return one if we
are having multiplication, division ought to be higher
percentage than in that case. I simply returning yes. If we stood up is we know that it is greater as
compared to other operators. So we are returning.
If you call, what will happen actually if
you call the same function, let me tell you in that manner
then you'll learn to stand it is in this case,
you can see here. Yes. V-naught, if both
of them are same, like the skeleton one, top of the stack without having no operator S raised to it. If I don't call out
the units dysfunction if I use in this priority. And then in round brackets, symbolic rate is
greater than pilot your stack on the
top, I'm falling. If I call the same function, we know that in that
case what will happen? It will be ignore that the
parity operator is two, but we are returning is, we are returning
as the editing is. For that case, what will happen to you running S3? What will happen in
that case, it may be, don't you create a different
country like this? So here, if we don't create rarity underscore
incoming symbolically, all the same function that is priority and hence involved. And I've checked the
condition greater than parity of the
stack of the top, be knowing that if I
call the same function, both of them will return S3. So this condition will not be satisfied because this will
be returning as three. This will be also
returning it's three, then this condition
will be not satisfied and we will be spending
more time doing. If the associativity is right
to left, then I'm punchy. Whatever we want
will not happen. So net board, what I have done, I have created or the print function priority incoming
signal, it's in bold. Only when we can
symbolise reads two. And if we get the top of the
stack as the stool and only I will call this function
variety of incoming symbol. And for the symbolic links to what this priority
of incoming symbol, if it is greater than that of the rarity of the
top of the stack, then only I will, which discounts in Poland to
the top of the stack. So what is this incoming symbol? This is the incoming.
You can see here. In this incoming symbol, I have written this sketch
and ball and retain. It doesn't manage this
and simply return for what will happen when
this function is called, then this will return it or bought this symbol that
is for the REI store. But for this priority function, that is this symbol
when it is these two. You can see here
we are returning again for this scans and
ball incoming symbol. I'm returning for the Vedas or this priority for the
top of the stack, I'm returning three because I'm calling the priority
function that returns three. So what will happen
in that case? You can see that is stuff
on syllables which are row. What will happen? In that case? You can see here it is
incoming symbol will return false because we
have already done the cognition and this
gravity is returning. This condition will be satisfied because four is
greater than three. This vendor done for and
disability are done three. So for descriptor than three, this condition is satisfied. Violin boot. We want
the same thing. And then we simply push scans and bolded as raise two
on to the top of the stack. So we know that whenever
there is a race to the end, symbol and top of the
stack array is two. Then we're simply supposed to push this Canson
ball onto the stack. So therefore, we are
doing the same thing. So we are simply good. We're creating different
function which will return all the
same tim volume. It will return a
greater priority. So that means this
condition will be satisfied and then
we will be pushing. Now, once this happens, then we would simply
do the break. So we don't want other
things to happen. That means this will
come out and then again, symbolic will be scattered. But this is not the case. That is if we are not
having the scans in bolus, these two as well as we
are not having the top of the stack as race to
the top of the stack, as well as scansion
Baldi are not least two, then in that case this
condition will not satisfy. This condition will be checked. So this condition is ponder the associativity
that is left to right. So in that case, what
we will be taking, first of all, we will
be checking that. In that case, we will be
simply checking postdoc or whether the stack
is empty or not. Why I'm checking the
stack is empty or not, because we know that this
condition, which is that, well, first of all, and this is what we are checking
with the gravity. So if the polarity of the, of this gang symbol, you can see if it is
necessary as compared to that of the priority
on top of the stack. That is what we are
supposed student, we know we are simply supports
to borrow from the top of the stack and we're
supposed to templet stored in the resulting
postfix expression. Also, it is equilibrium. The vanity of the
scans and monitor is equal to priority of
the top of the stack. In that case also for
the associativity, that is for bother Associativity that is
for left to right, we're simply supposed to fall, we're not supposed to,
which becomes water associated if the
gravities are same. But if the associativity
in the predators are same, specific duties right to left. In that case, we are
supposed to push. But if the polarities
are seeing that is here, you can see object or equal to, but here I've considered associativity to left to right and we're
supposed to pump. Because what right-to-left
associated in here itself, I have j and I have
simply given the brakes, it will come if this
condition is not satisfied, that means you can
consider the associate. Fancy than that. This
we will be taking also what associativity
is left to right. Associativity comes
into picture on leave and your
priorities are seen. So if you are having the scans
and boil priority lesser, you can see here
we have checking lesser them that off
the top of the stack. Enemy, yes, and please
support to the top of the stack and stored in this result in
postfix expression. But if it is equipped with, then also we're supposed
to fall because we are considering here the
associativity as Neptune, right? This is what, and then by
averaging this while furniture, because we know
that we are simply, if we are having this canceling all priority less than the top of the stack image. Suppose we have to
keep on popping till we get the priority of
these gangs involved. Grateful. Even if VIP disparity of these scans and ball is nestled
in the top of the stack, will be involved the
top of the stack. So we will then there will
be a new pop off the stack. So it will be the Andrea and human which
is dead in the stack. Again, we will be checking the priority with that
top on this check, again, if we find the scans and
more priority lesser, again, we will be posting
the top of the stack. This we will be, keep on
doing the same thing. In this priority will
be until we get this parity lesser than
this gang symbol lesser than the rarity
of the top of the stack. Once this condition
is not satisfied, that means a priority on the scans symbolic if
it is greater than, this condition will not
be executed, not both. And then finally,
we will be putting this symbol onto the stack. So this is what we are
doing in this case. You can see here, first of all, I had made this for
access to your user. You can simply or simply
checking, you can simply copy, paste the same code, and execute in your code
block ID and see the result. You can simply do it for the
same code, the same scene, the one cleaning you,
simply medium available. What we are doing. I
hope so you understood the four different
strategies may never operators the scans
and Walter operators what we as opposed to conversion
off and fixed to fix. This is what we're supposed to do when we get this embolus. Africa's. Now the next thing is that
what we have checked it now, we have to check opening. A round bracket closing. We have checked
for the operators. Now the last that
is the default one. What does the department we know the default minus your operands. We know whenever you get the
scans involved as operands, what we as opposed to Julia
simply supposed to store it in node is I didn't
expect Edit expression. It is a little more
splits explanation. And that is area because
there is this that's involved UBI simply stored in it
in this postfix area. And we will be incrementing. The people who split. This beam will be
incrementing because how we will be stored once we spawned a symbol in this array, then we will
implement so that the next time when we add
this symbol organism, whenever doctrine
comes again the same, all that's involved will be
stored in debt, was eaten. And that is the reason yet we, as opposed to increment men, we store the symbol and that
physician or the editor. This is what we are doing in the defaults with we know
that whenever we get, let us aid or simply
store it in suspects. Expedition. I hope so you want this whole
thing and that is fixable, would speak to experts. And finally, since this is
what we are taking a for-loop, this we are, we're
supposed to do one-by-one. This for the 0th element
by element taken, all this will be reached till the end that is bringing them. That is a reason we are
giving this condition, string length of the
infix expression of the scan on these symbols. Once we run the whole
expression scan, the for-loop gets
comes to the end. In that case, what will happen? In that case still
we have to check that this is outside
the for loop. Because one PR events
or we are finished once we are done with
complete scanning of the Wilkin fixed
exploration ones, the for-loop comes to
the n. In that case, still be able to protect
your stack is empty or not. We have seen that if
the stack is not empty, then we have to simply pop
from the stack and we have pre-stored in this result
in postfix expression. So this is the reason I've
given this while loop. We have to put all the
elements one by one. We don't get this stack empty and you have
to simply stored in this was fixed expression
that is added expedition, So that is one that
will be executed. Finally, finally, you will get the result in postfix expression
and we have to simply add this null character and the large don't
dispose fixed, Eddie. This is how you will get
your course fixed, edit, fill in this function that is in this fictional or expects. And finally, how we are calling this infix to postfix
from the main function. We are passing
this, we have seen we're passing this
in fixed explosion is postfix was not having anything when we called
from the main function. Once this function is called
in Pix2Pix fixed months, this lagging strand, these are all instructions are executed. Finally, you will get the
result in false fixed erythema. And finally, the span dysfunction
comes to when it comes, it will go to the main
function where from Merritt, what's called it was called from this main function,
that is from this, from this line, it has gone from here and you will get the sports
fixed edit film. And by what you are doing,
I'm simply deserved. Bringing this up is
to print the value. You can actually even simply display an error
message if you have a blueprint for value
can give in this manner. So this is what this end l
is status in the new liner, this value to be printed. And then once I get this result in postfix
expression painted on this program and talk on motion of infix to
postfix expression. As well as the program is
for also evaluation of a postfix expression
we have seen in other video how
to evaluate it. We know the concept
of evaluation. Let me just quickly device. So from this object that
is enforced into boats protect created here
I have called this function evaluation of both. And I have asked this result
in postfix expression, which I got from this
infix to postfix. What does evil
underscore post have? The input given to
sports is what we got. Let us come here to the function definition
of eval underscore post. It will return an integer, so this will return
your expression value. What it will do.
This, first of all, this infix expression is there. It will be converted to
those specs exploration so that we can see what
posts fixed expression we will be getting here. And that was fixed explanation. I'm boxing here in this function evaluated
in this course. Finally, that postfix expression will be evaluated and
you will get the result. Whatever you get the
result will be deserved. All finally, the user has given. In fixed expression and in our coding vf and wanting
to postfix expression. And then we are evaluating it. We've been seeing what will
be the result of this. So first of all,
you can see here, what is the, what is the logic for this evaluation of
a postfix or whatever? That what we're
supposed to do in this what is supposed to do in
this evaluation of postfix. We have seen that suppose I was supposed to get
this as a postfix. This is a postfix
expression which you want afterwards and margin
from infix to postfix. This is not postfix fixed
expression, which you get. Suppose this is a postfix
expression which you get. So first of all, we will be scanning it from left to right. We will be using a
for-loop for the same. Once we find the operator. Once we find the opposite, it is an offering photos and plus as an
operator to result. Once we find the operand, then we will simply
push it onto the stack. So here this will
be opposed it when we are evaluating the
full space exploration. In that case, in the stat we will be simply
watching her apparent. As we have seen, many
moles converting from in fixed or for space
exploration in the stack, we are pushing the operators,
not the operators, but this is a, consequently
evaluate, evaluate. When we scan from left to right, we may be getting one. And we get the sketch militia. When we get the scans and modus operandi or
simply supposed to push it onto the
top of the stack. Landscape. The operand APS
will push it onto the, onto the stack when we find another symbol as
an often again, you will be pushing
it onto the stack. When we find the operator. If we find the operator, we will be popping sometimes
one time when we pop, you know that recent but
element which we are, which was poached
very last minute, be both very fast. We know that this is a
concept of the stack. So that portfolios
fall will be formed. You will be collecting
in some variable. And then we will be again, we'll be working full-time. So it'll be popping why we
will be pumping two times so that we will collect this post for our
buck in some variable and another op in collect
in some variable. And this operator
which we bought, we would simply therefore what we will be doing
both two values. Then we will be
simply operating this plus in-between
this bobbed value. So that this will be, this will be the scenario. That is, suppose we get
the software standpoint, what we will do, the
poll function like this. Suppose in this video ability, this will be of the
caregiver type. And this again will be popping
me get for the first four. We get four because it can
be storing the last value. So since phosphate It's eight, then we pushed towards
affordability, the last element on the stack, so that will be very close
to one and default stops. And the second, second, both this eight will be formed and we will be simply
the operator which we got. We will be simply
only one function that forward how we will
be operating in this case, we will be simply calling
function and we will be checking if it is
a plus operator. Then in that case we will
be working like this. B plus B simply be is. So first of all, first of all, we have formed this and we
have collected in this game. And then second time you
are hoping we are connected and you can see the
order we're doing. B plus a b are not doing APSP. This is what we will be
evaluating in this manner. Again, that whatever result you get from the
breathless big beaker. So you know that from the plus, what we are getting actually, from P plus a, what we are
getting, we are getting 12. This resultant will be, will be simply again, pushing it onto the stack. What we will do and getting
me to scan the other symbol, next symbols, but the
next thing is true. It isn't. It is fail-stop all
the Nazi moles, they are simply pushing this
operate it is an operand, so we will be pushing
it onto the stack. Again, we will address
embolus to be again, pushing it on top of the stack. Once we get the raise two, then we will simply pop
elements from the stack. So this is how we will be
working and we will be simply checking for this
race to the function. That function, let me be, we can simply have given
you a switch case. What we will do this sport plus you have seen
me God Ford here. We got here. How are you
going to be operating? So first of all, we will be operating
as b plus a. You can see the order first, second year pork order. You can see we are doing
this explanation b plus a. So we will give the
switch case better. If it is plus, then we will be simply
evaluating in this order. We will use this operator plus. And really it in the order will be plus a n
naught a plus B. So the order is very
much important because the next time that we see how to convert the infix
puppet effect. And that is the, we have to also check what
will be the order. In that case, this order you have this orbit is very much important. That is b plus a. So that's what we
will write this. Which case if it is
a plus operator, if it is a race to operator, if it is a minus, if
it is the region. So for all these operators, we will be doing the
switch case and we will be writing the expression
in this industry. So you can see here, let us come to the function
and see now. So first of all, in this
evaluate and score post, you can see we have taken a
for-loop via picking up on you because I'm
scanning the wolf was fixed expression one-by-one, each symbol from left to right. I'm checking if this
condition I have, I'm taking in this region, that is if it is done on
blood from 0 to nine, then that is if it is an operand and we
are simply calling which function we
will simply push that operate on to the stack. If it is not 0 to nine, if it is not a number, if it is not an open, then it will go to
the else condition. And that means it
is an operator. It will be two times so far the first ball I'm
collecting in the variability. What does this variability? It is older. You can see here, this is why I'm an longer
requisite this end. We are taking this
expression as a number. We're not making the
expression as a character. So therefore I'm
using a long int, read an extra unmuting
long in folder, or declare, declaring the
variable that is eNB depth. I'm considering this
expression which is having the numbers
and not the characters. So this is the, this you
have to keep in mind. We are taking the
expression that was fixed expression
as a number. If you're not taking
in terms of this, we are substituting the
values for the expression. Before we are
collecting in this a and the next block we are
connecting into this variable. Then we are using the suitcase, this switch cases for what? If you are checking whether
this then we are copying. That is for this. You've caught up on,
you are storing this. When you get gave
you guys some people watching on this condition
will be satisfied. That is this. If condition will be satisfied. If it is an operand,
if this folder, it will again, condition
will be satisfied. The login push it next time. Unless involved will rescan. I evaluate for the, for the for loop at this board will be scanned.
It is an operator. Condition is not
being satisfied. Else condition in which satisfiability popping
from the stack, whatever we have 42
times involved in this. That is for this operator will see whether it is
a plus operator, debit autism minus
ordinary type. It is a multiplication. If it is a division, if it wasn't age, like if it is array student. This we simply evaluate
in this manner. You can see the order. Then is that in-between
this operator, whatever the scanning symbol. Again, you can see
because I minus this, again for the order
is b minus a. If it is a multiplication
owners bead. So you have to send the
result which will get you use stored in
the stem, so on. So it is all of the datatype elongated
because it dissolves and the data type and you have your doing
putting the brakes everywhere. And finally the
resultant, the result. Each time the result you get, suppose you bought
some reason than the biggest happens and then
you are pushing this stem. Whatever the result you
get from B plus a result, the net is this one, B plus EUS looting. In this step, you will be
pushing onto the stack. Again, you will be scanning. And the other symbol on this end often you will simply
push it onto the stack. If it is not an open-ended
is an operator, you will pump the values we have already seen
in on the whiteboard. How does evaluation happens? Finally, when you are scanning the whole false
fixed exploration, evaluating the whole expression, when you are done with that, in that is you will read
your in your stack. That will be uneven
venues we witness and bleed benefit from the
stack and you will be. In this result. So that will be also
on the datatype long because it
will be an integer. And finally, you
will be returning this value that is
already valuable on, but after the evaluation of the expression
and you will be returning that value
that is returned result. That it will be returned
from where it was called. It was called from
this position, from this line in
the main function. So when we are
collecting in this file, you can see I've
taken this long int, and finally, I'm printing
this value. You can see here. I've hoped so you understood
how to convert in fixed tool was fixed
as well as how to evaluate it was
fixed expression. And we are done with checking
with the priorities when, if it is an operator, when we convert infix to
postfix to all these fancy, we have seen what should be the result of this
final exploration. We are taking this in fixed
expedition in the example. That is all should
be first of all, you know that first of all, how, what will be result
internal event when we just cross-check so
we know that this parenthesis me just manually, let me just manually calculate the result
of this explanation. We are not using the stack
just to find out what will be the result so that
whatever coding we are done, we are doing, we are getting
the same result or not. So we know that this will
be executed manually. Evaluate this exploration
without using this tax or this, you know that this
what will happen, eight plus or minus two days to six divided by two plus. First of all, this should be evaluated if
evaluated manually superpose. We know this will not
evaluate cost because supposed to restrict who is debits having higher priority. So today's include
having high purity. This will be evaluated
and not this one. So therefore, it will
be in this manner. We are doing manually
this order BY you can do this to find out whatever
result we get from this. Villi should be the same. What we have done
that with the coding. So in the boarding the
logic is different. You're not scanning the world
expression again and again. It isn't easy and we're
working from an old speaks using the stack so that we don't need to do
all these steps. I am doing this just to find
out the results of whatever. When I execute my program
and we execute our program, then the results
should be the same. Just to cross check
what is the result of this illustration I'm
showing this manner. You can see here like this. Then again, the same thing. It will be like this. That is, it will be plus, so it will be simply six here. Then finally, finally
it will be simply, you can see here, this will be, then, if you see here, this will be so if BCC here, this will be minus plus six. So therefore it will be simply
this expression will be. Finally, it should give
me the explanation is 17. Just to check what would
be the result of this, you can already calculate
the result of this. You will get the result
of this as like the 17th, the program that you are done, we know that what we are doing, we are converting this
in fixed too, is fixed. We are converting
infix to postfix. We are converting in
this manner in which you can see parentheses or not. And we will be scanning
from left to right in one group and we'll
be evaluating it. So therefore it is very faster because we
are using the stack. That is the reason you are
converting the infix to postfix using the stack
because it is very efficient. And in one more, we can evaluate the
resulting expression. You can see how you have seen
how he ever been evaluated. So the result
should be the same. That is, when we execute, we should get 17 the same
as we have seen how we got. Let us simply execute. We know how to execute in this view that to
get the loss value, you can simply see here, I have checked this loss. When you check this
loss in the view, then you will get the, you
already see the belonged here, whatever better you are getting
an a compilation error. Or if there is no error, then you are pretty good for
running the same program. If it is not in the data and
whoever than Mellon good, you can simply
execute your program. You can send these
on your program. Therefore, I will
simply just a second. I'm simply combine
the current file. You can see here,
there are no arrows, so that means I
can simply run it. But then you can see here in the building and run the font sizes are
very large and very small. It is ridden infix to postfix and evaluation
of the postfix and enter in fixed this message I have written in
the main function, or you can see
7. Infix to Prefix Conversion & Evaluation of Prefix Expression C & C++ Session6: Hi, welcome to the new
session for writing the program and executing bought infects do
prefix button budget, as well as evaluation of the same resultant
prefix expression which we obtain after conversion on this
fixture prefix will be writing program and executing in C as well as C plus plus Windows
operating system. I hope so you have gone through the earlier session where we
have seen we have written the program as well as
executed for infection was fixed margin and we have evaluated for the
postfix exploration. Let us see the scene or
the prefix expression two, that is conversion of
been fixed to produce an evaluation of the scene. Here we will be considering
the same, in fact, expedition which
I have on sort of taken on the audio session icon, wanting to postfix explanations that are given to understand it rolled back but the
same fixed explanation. And as you know that we have covered in a
couple of sessions, what is the fixed expedition? We know what that infects
expedition depending upon the position
of the operator, it will decide that an
expression is in face, but it fixed or pore space in fixed, meaning the operators. It is present in
between the operand. So this is an infix
expression. You can see here. In-between 84, raised
stupor is busy with me to divide as president
between 62 and so on. We know the object and by
the ICA in fixed to perfect. The reason behind is that we know that if there is
an infix expression, then evaluation takes lots of
it is very time consuming. That is a reason via the
in, from infects pseudo, prefix and login using the stack because tax plays an
important role in order to evaluate the expression very
weakly positive built on what we'll be working to
the prefix using the, if, we can convert
infix to prefix. And in this prefix, the prefix which
we'll be getting, there will be no parentheses
and the priorities will be arranged in
the sequence order. And so then we scan it, didn't want to go,
we don't need to. It will lead us. It'll be on the board. You don't need to do
the repeated scans. This is how it avoids
the time consumption. And that is the reason we
are using the stack here. So these are the
applications which we have already seen for the stack. That is, application is that in order to
evaluate the expression many fats that are
different types of convergence in Pix2Pix,
in fixed reports, fixed. So these are the application
on the stacks and movie. I think the program and
executing for this program. So let's move on to the or
blocks or for this detector, which is required is very easy. You just need to download the code block and you
need to install it. It's freely available. After downloading and
installing the woodblock, just open a new project and see, suppose we will be seeing
the same pilgrimage, be able to recover
on your section on the whiteboard for
this fixed IP prefix and the evaluation tool here. Moving to the code block, I have already created
a new project or in Fitzgerald prefix can login as well as for the evaluation. So this program will
be covering two parts. First of all, milk and
what and fixed to prefix. Then we will be evaluating
the result entry picks, which so far I stop on the menu create approved
day for C plus plus. This is your domain, dot cpp. Suppose we will be
seeing the program and executing for the C plus plus. And then you will be also seeing the program and policy language
and maybe executing it. So this will end. I will also make the
board available to you. So you can simply copy, paste the same piece of code
and execute on your answer. It will be better if
you do the hands-on so that you will understand
the concept more easily. Let's see. This is main.cpp, CPP for them, for this program. Here. First of all, you have to include all include all these header files
which are required. So I have included iostream, mad Gore-Tex, all these header
files which are required. What are the inputs
we have already seen in earlier session inputs which are required first of all, being really required
one stack using every. Then you require one
another area where we will be storing one by
one, we will be storing. This involves storing within
the prefix explanation. So therefore, one area is required for the
prefix expression, one character is
required, and one area, as I told that stack using
arrays also required to do. Then finally one more
that is required that is fixed to restore the
infix expression. The duet is my daddy are
in fixed expression. One Eddie for prefix expression. One stack using EDI is required. So all these three
things are required. And I don't know. And out of bed or operations which are
performed on the stack. We know that which
operation pop operation. These are the
operations which are required for the stack. And the domino that
top will be always deferring to the
element on the stack. So to the Gulf wars and
human element we just pushed really lost
when we bought very first we know this concept,
taught this deck right? Now. This is your row C plus
plus main.cpp file. First of all, here we
know that in case of the glass C plus plus program
via be required class, I have created here the class
by the name in fixed tool, but he fixed this class
and fixture prefix. You can see here I have made on the member
functions as public. So this is a public
access specifier. I have created the
constructor and destructor functions
without required. I have declared the oblique, that is the membrane
Radiodurans. You can see I had made as
brightening this look nice, which I'm going to be using,
but in fixed IP prefix. Now, which functions are used in this glass you can see
the required push. Yes, we require a ball. Then we require in fixture prolific since we
in this function, it will be converting from in fixed expression to
prefix expression. So dysfunction is
going to do the same. Then the another
function that is evil underscore prefix that will be evaluating the result
in prefix expression, which we then another function floridly so we know
that we have been, what is the help us
solve the priority. So whenever there
is an operator, then we will be
checking the rarity of the incoming symbol with that of the priority of
people for the stack. So we know that we
have already seen in an earlier session what
are the incoming symbols, though, in fixed exploration in between these
scanning one-by-one, each character will be
your symbols first of all, and that is denoted
by scans inborn, that priority we will
be checking with that of the priority on
top of the stack. We know the top of the
stack will be the reason. And even that was pushed. So that will be the top of you will be comparing a backup, somebody without that,
if you're on the top of the stack and then it
will start different. Sebastopol. Come back to that topic in fixed or false fixed
conversion so far tougher. Let's go main.cpp. We have seen now for the
class which functions are used just in second
in this class? In this class, then once I
use this function is empty. We check whether the
stack is empty or not because if you are performing
the pop operation, we have to first check whether
the stack is empty or not. This stack is empty, began
odd ball height, then end up. Then. Then see here the
private access specifier, what all these member variables are there and that is
white underscore space. We will see what is
the purpose of that. Then another video,
this long instructor. So here we are using the stack
and this we will be using. Here you can see
here the stack which we'll be using this
as a stack using EDI. And therefore you
can see I have used this subscript and this is max. So this is a stack
using edit exist static edit in which you have to define this ice
enter compile-time. What does this max? We have, we have already
defined the size of the stack. You can give you compile them. You have to
give this size. You can change the size of
the stack and an anti cancer. And their top dope
is referring to the recent element of the stack. Now one thing is
dead in this program important fixed to
prefix conversion though stack datatype is on the long and it is not on good
data type character. So what might this data type is longer because we have
already seen or used session in on the whiteboard that while converting from in fixed to prefix and motion
was to fall in this stack, we will be storing operants and we will be
not storing up operators. So in case of no infix
to postfix conversion, what he was doing, it
was totally different. The stack we are
storing the operators. In case of the infix
to postfix conversion, we are not storing the operators
on the stat yesterday, the operands that we're the operands which will be
there since we will be u, v will be directly
substituting it with numbers, that is with the values and the depth order the numbers
out of the datatype longing. And therefore we are
taking the stack as long and since we're storing
operands on the stack, so I won't tell you what
the difference between this fixed to prefix
and infix to postfix. If you have gone through the video sessions,
couple of sessions. Now. Now just we have seen clause
and fixed duplicates. Now, moving on to the
main dot CPP file, which is a main image is
a mean function on this. Last, whenever you Execute your program. The control comes in this main function and
nine by nine instructions, and it'll be, all
these instructions will be executed sequentially. And you can see here in
the very first line I pick indigo is convicts to store
that in fixed explanation. That will be at a
detailed guide. And that way you can see the
IU is a character and we are writing this up code by
audit locating the Adi. And then another
area we are using prefects so that it
isn't able to be stored in one by one in this
prefix adding disability that is ultimately effects of the gun voting in fixed too. So two areas are required. For now. We will display the message CLV. Know that SEO is to display the message on the
console in C plus plus. It is saying in
fixed to prefix and evaluation of prefix
in C plus plus. So this is a C plus plus program is done in
the C plus plus. This is just a message
on the console. Then we are using logins. You'll see what is
the purpose of it and enter the infix expression. We are displaying this
message on the console. Once this message
comes on the console, user will understand
that user this holds true and the infix expression, so you're observing
enter the expression. So that is a reason we're calling this getter dysfunction. In this in fixed. Whatever expression the
user get on the pencil will be stored in
this in fixed adding. Now this infix headache will be the input function that
is in fixed to prefix, whatever function we
will be defining, releasing the
definition of that. But we know that in
fixture prefix function, the input an infix expression. So for that meeting, what coding is required for, since this is a class
that I've created, then I have to
call them fixed to prefix functions of waterfall
and create the object, static object of the class and fixture prefix
in this manner, this is my object and
do not buy this object. I'm calling the function that
is in fixed tool perfects. And I'm passing this eddies
that is in fixed and prefix. So this fixed cost of one, this is the input expression which using them and
not on the console. So this is the constraint, the same fixed expedition,
which I have shown. This as a false argument. The second argument, perfect. So this is nothing that
will pass as it is. Simply characterize
research will be filled in this function. It's there. Let's move
on to this and fixed it. We fixed. And let's see what coding
is required. That function. In case of the fixed prefix, this approach argument isn't fixed expression
and secondary human is your prefix expression. That is the, that is the
result in prefix expression. So you can see I've given
the name by the RDB. Flip it. I will tell you what. I am given this name, but this will be the result
in prefix expression. First of all, we have seen in the earlier session
on the whiteboard while converting to
infix prefix false. The main thing is that just
added move on to the notepad. In fixed expedition, which we will be giving unconstrained the same example which I
consider infix to postfix also the same in fixed if
we indent on the console. In that case, suppose
the following expression either be post or reversing. So what is the logic? We have two volts reverse this whole expression
one by one. So that is converting fixed. Fix. The medieval exchanges. What is after reversing in
fixed walk even get this last node's got activated possible resistor
ordering the edit is one thing is stored in. The last will be stored
as a 0 or deletion in. And if you know that
at indexing starts from 0 to n minus one, so therefore it will
be in this metal. Then second Nasdaq
is two we have already seen in the
diagram on the whiteboard. It will be stored, it will
be stored in a second. It'll be the second element. Then this is going to
be the land is two will be minus then two and so on. You can see you and this
is the octet reversing. You will get this
expedition as like this. So after reversing, even get
this expression like this. And now you will be scanning this expression
from this as it is, that is from Neptune, right? So we obtain this reverse
fixed expression. Now the expression you will be scanning from left
to right, so forth. Conversion of in fixed to prefix the input port on your
session or conversion part in fixture for speaks
me don't require to reverse this string. Vr simply scanning
from left to right. But in case of conversion
are fixed with lipids, we have to reverse the string
and that is corrected edit. Once we, once we get the
reverse character array, then we will be scanning
from left to right. Then the process
will be the same, but we have to reverse it post. Coming to the program here, we are declaring
some variables here. You'll see what is the
purpose of these variables. You can see here, I have
taken one character array. Even see what are the
use of these videos? Follow along even
see now this one. Let us character array. You have seen the
IDB IN, infects. Why I'm big in this video, but as I told you that
in fixed which is there, I will be reversing it. So therefore, I have named by this name this character
areas RDB vivo in fixed. Restore that the reverse of
this ambiguous in this edit, this prefix actually,
what it is. We will see the old
result B2B obtain. You've been stored
here one-by-one, this prefix, right
after converting. So after applying
the list one by one, we will be storing symbols
in the prefix expression. So therefore we are
taking a character array. Now, this logic is used
to reverse in fixed, which is the code in order to reverse
it as an amino deck, how to reverse a characteristic, we have to suggest the for-loop
from M2 0 position and the act since we know that the end element will
be the 0th element. And therefore you can see
I've taken the for loop. I've started from streamlined
in fixed minus one. So therefore, I indexing will be the index of
the last element. And then we have to decrement. You can see here
I am decrementing one-by-one I minus,
minus the impacts. And what is this? K is equal to 0 V.
I've seen that since we will be storing this new Adi, that is RGB pixel, therefore it's indexing
starts from 0 to n minus one. So the last element of this stored this 0th position,
this new Eddie. And there could be a
ticking kids equal to 0 while this IDB infects. And then we also
incrementing for this case. So because we will be stalling button by one last element
to the 0 position. Therefore, we are
taking iron key. I will be referring to this infix actually
that started from last. So therefore, I is equal
to string in fixed minus one and k is equal to 0 because we are restoring
in this new Eddie, therefore, index
millimeter, the zeros in restoring and the 0th
index of the new Eddie. So therefore you can see
here is fixed, that is I. So I will be since
IV as typing from the last index of
the array that is of the impacts that
this last element will be stored as a 0 and
human on this new area. So therefore k is
equal to 0 initially. Then after the
execution of this line, then the I gets decremented by one and that gets
incremented by one. Now I, therefore, this
condition will be checked. That is, whether I is greater or equal to 0, it will
be good it does. So we have to do this in
reverse from n to 0 position. Therefore, this condition
is checked in IV just to 0. We have to keep on storing one-by-one the element
in the new element in x. So this is how we are doing
this outreach and is used to reverse the infix expression. As I told you that. First we will be reversing the infix expression
after we obtain, after this ONE execution
began the reverse string and we will be appending
a null character in this result in diverse
in fixed expression. Now I've just printed it the reverse and
fixed expression. So I should get as like this. Now we will be scanning
from left to right. And therefore we are
taking the four, we are taking the for-loop in which will be the
switch case by such case, because there are
different fluids, which we have to check. If we get a closing parenthesis, we get an opening parenthesis. All these rules
are that if we get the operators that is like this, if we geta operands,
operands is default. So therefore the search
space is must for the same or to check
what all the roots. And this will be scanning
this and it's all done in divorce and fixed exploration from left-to-right
definitely started. The formula is equal to 0 I less than string
length of this. We've always infix expression. So now we have seen for the early apart in
fixed reports, fixed that. Now we will see what we have already seen the also the
words on the whiteboard, but in Pix2Pix,
what are the ruins? Let me device quickly
washed up on the lease out that this is your reverse
in fixed explanation, which you have to scan
from this left to right. So first of all, when you get the closing parenthesis for conversion of in
fixed to clip x, in that case, you
have present bleed. Bush this closing
parenthesis onto the stack. We have seen that the ending
value most converting into we have seen that
when he was unloading. We have seen that when he was in fixed reports fix Monday god, opening parenthesis, then we're supposed to
push, don't need better. This is onto the stack. In the case of
conversion of Pix2Pix, it is important we have then we find the
closing parenthesis, then we have to push
it onto the staff. Definitely have seen
also on the whiteboard. Now, this is the best
rule when we get, then another one is
that when we get this opening pattern persists, then we have to put
all the elements from the stack month
by month till you get this losing bet instances. This is also the depth of the infix to postfix in fixed reports fits
what he was having. Men began closing
parenthesis then we supposed to fall upon the elements till we get
to opening material. Men began opening parenthesis. Then you have to walk
all the elements till we get to round brackets. So this is the difference
in case of fixed IP prefix. No. Then we get, when we get the numbers down
here to simply push it. Therefore, we have
seen so many get, we get the operands S2 as that. Then we have presumably
stored it in the body fixed expression that is in the prefix corrected. When we get an operator
like we get this race to this minus or this plus this plus division
on these operators. Then we have to deal
with that on the stack. Then the picture comes
on the priority. We have to check the
priority of these scans and one of the priority of
the top of the stack. First of all, what are those? What are those?
For the operators? If we notice first
start one by one. Which case then
you'll understand. So first of all, we
have already seen in audio session on the whiteboard,
we have already under. I've already explained
you the folding detail, but let's repeat again and shot. Let's move quickly. Because the main objective of this session is true execute
potential the output. So animal and so I have shared the same food so
that you can copy, paste the same code and
run it at your end. For C plus plus N4, C9, which this for-loop
which is dead as it will be up to scan
this derivatives in fixed explanation. I'm scanning this one by one. I have taken the for loop. Now I will be storing
this reverse that decided to be stored in each
character, each character. And I will be checking. And Isaac way to 0. That gives you in
fixed subscript 0, the zeros element,
that is this one. That is this one going
to be like this. This is zeros element of this diverse in fixed expedition
one-by-one each connected, ideally scanning and seeing. Which rule does it fixed. So therefore, you can see here I've collected
in this symbol. This involved is the
datatype character. You can see the symbolism
of the datatype character. Now. Now I am proceeding with, I'm proceeding with this things. So I have put the if condition. I have already mentioned. The purpose of this whitespace
dysfunction is there. So what this function
will be doing and show you this is a function. So you can see I've
mentioned the name of the class and thus
scope resolution. And because I'm defining the
function outside the class, therefore I'm using
this class named scope resolution and name of the
function I'm defining. So first of all,
you can see here the main objective of
dysfunction is debt. If you're seeing born because of blank or
if it is static, then it will return 1. First of all, we have to
ignore me up to not scan. Suppose you get like this, after divorcing expression,
you'll get like this. Suppose that have
given like this. After divorcing, you
will get like this. You can see when you
added this lemon, No problem, when
you are at this. This is a space where you have to ignore the
space you don't need. There are no rules
for this face so that you have written
the function, right? And the squarespace.com and check if it is a space or a tab, then simply we will return one. And then in this if
condition is satisfied. So you can see here
this if condition is this IP can be cumin not satisfied and
even not check for the roots. We have to avoid impacts of
whitespace and proceed with the next Next step
element of this EDI. Now, let us think so. Therefore we have
put the switch case in this if condition now, switch symbol and the symbol, we'll see if it is, if it is a closing parenthesis, we know we're supposed to
simply push it onto the stack. How, what is the
function of the push? In case of the stack, we have seen just since
this weekly moving, this repeating what is false, which means simply it is
an operation on the stack. Whatever symbol you push here, we have to force people
pushing you up to see whether your
stack is full or not. If the top is greater than max, then you have to give
them a seat. You cannot. A stack overflow you
that you are not and you cannot
push in that case, so you have to simply exit. The stack is not this
condition is not satisfied. That is, there is some
space on the stack. Then in that case you
will simply the stack, you install the symbol and then this top will
be incremented. Know, moving through the
function again, then break. So if you get done,
in other cases, 40, Uganda opening parenthesis,
then you have to poke, you get this closing
parenthesis. So therefore, this condition
is that you have to keep on pumping and you have to keep on scrolling
in this prefix, exploration and drilling
human p plus plus. So this is in this App Store, do formed evaluates
to false menu and the bendy false media we're collecting in
the formula when you, what is this positive value? It is the datatype get. We are storing that and then that formed the value stored
in the prefix one-by-one. So this will be popped
and stored in the prefix. It'll be don't get
this opening paren. Once we get opening parenthesis, this condition
cannot be satisfied. And then I would say this while loop and
this break is applied. Now other rules are
for the operators. Once we get less operated on, we get minus multiplication
division mode. You can see there are
no breaks directly. This instructions are there. In strong, the same
instruction will be executed for all these cases instead
are no brain brachial. Now, what does this
instruction we'll, first off, what does it, what does it roof
on the operators? They don't know about? Because in case of in fixed
with prefix conversion, then we get random priority. Although let me come
here when the polarity, suppose this is Amanda D. Let's consider if you get any
operator like raise to minus, plus the priority of the scans
and wondered is of this. Suppose this is
your scans symbols. If this reality, if it is less than that of the
pop from the stack, then it is lesser than the priority of
the top of the stack. So in your stack that is, the top will be the last
element which was poached. The end that will be
the operator on me. So you have to check
the priority of the scans and born
that is this one. Here would actually then with that of the rarity of the
top of this Internet. So if this parity of
the scan symbol is lesser than the priority of the top of the
stack in this time. And I divided it over
the top of this diagram. We are simply supposed to
fall the top of the stack and we're supposed to simply store it in the
prefix expression. That another rule is
this priority on D. I'm just mentioning
you that ruins for the for the operators,
the priority, the scans symbol, it is greater or equal to priority of
the top of the stack. And that gives me up to simply
push the scans and staff. So these are the roots. You can see this is if you match with that of the conversion of
infix to postfix, this rule, if the priority
of the scans and ball is lesser than the priority or the top of the stack to save. If you check with
that of the priority. Or again, if you want to check this rule that
if the clarity of their scans we want
is greater than that of the priority of
the top of the stack. That is also somebody
as opposed to push them scans and one
onto the stack. But that rule is different
than the priority of this scans and bull is equal to the priority of
the top of the stack, then we are not
supposed to fall. In that in the case of
in fixed reports, fixed, recheck the associativity,
then it might go. But here we will simply push it scans and ball
onto the stack. This is a dependence in
the control in disarray. So therefore you can see here this foundation
which is first of all, checking whether in
this while condition, while loop is there, what
does this while loop forward? So first of all, this is for us to check whether your stack is empty or not because we'll
perform the pop operation, we will be checking post in the clarity of these
scans symbol is necessary and the polarity of the top of the stack
them, it'll be popping. So before PEPFAR being, you have to always check whether your stack
is empty or not. That is, if the stack is empty, there is nothing
president, you cannot go. What is this empty function? Let me show you your discord is I had made available to you. You can simply copy paste it. You can access it. What does this empty is empty. We'll check if your
topic is minus one, then it will return
one else, return 0. Then this loop is for
that, that is repost. You will check whether your
stack is empty or not. Then you will check
your clarity of the scans symbol if
it is necessary. If it is lesser than that of the rarity of this
tack on the top. This disparity function we have already seen
in earlier session, it will simply return the
priority of the operators. So if this scan symbol, suppose if it is plus and if you are a stack of their
top is multiplication, we know that the plus
operator is having the lesser priority as compared
to the multiplication. That would show you
the clarity function. So you're going to
understand it more weakly. I've already shown
you multiple times. Just to repeat. This is your priority function. Here you can see again
there is a switch case, so there are
different varieties. If it is a closing parenthesis, I'm returning 0 because we have seen the advent that there is a
closing parenthesis. We have present people shift
onto the stack or plus, minus and returning one. Multiplication division
was indeed I am returning to for at least two
and you're done in three. You can see here the cities. This one is having the highest priority as compared
to the other operators. So you can see here, this is just a different
return values. Now, if you see here that in
this case what will happen? Just, let me show you
check the priority here. You check the priority or
the priority of the symbol. It is lesser than
the polarity of the stop of this tag here. As I told you, if it is plus and this is a multiplication, this condition will
be satisfied and this tag will be formed and will be
stored in this effects. This you have to keep on doing till you find
the priority of the scans in bold lesser than the priority of the
top of the stack, minus the polarity of
those scans and bone is greater than the validity
of the top of the stack, then this condition
will not be satisfied. We come out of the loop, your scans in blood that will
be pushed onto the stack. I hope so. You understood. One more thing is, what
about when you are priority of this in my duplication, if your scans and bond is multiplication and the
top of the stack is plus, in that case, first of all, this condition will
not be satisfied. This is multiplication,
this is multiplication. This is top of the stack AS because this multiplication is having higher priority two, this condition, I'm just seeing different,
different rules. What will happen in
the priority changes, whether what this condition
will be satisfied or not. So there is a reason I'm just mentioning
different routes. So if the scans and maleness multiplication and at the top of the stack is plus, then this condition
will not be satisfied and this while loop will not be executed that it
leads you on SAP, you are pushing
the scans in boy, onto the top of the stack. You can understand
where the priority of these scans and bold is greater or if it is equal to the priority
of the top of this, then only this condition
by loop will be executed. And therefore you've
been recently pushing the scans involved onto
the top of the stack. This is what it will happen. So you understood
what will happen, then there are
different operators. Now the point that is actually in place all the
default, what will happen? The pole will be
if anyone having these scans in bold
as our openings. In that case, you've been simply prints on your
result in prefix. Therefore, the default cases for the same to
store the if there are often simply store it
onto this prefix edit. These are the dependent
rules for all these, oh, this parenthesis operators
end for the operands. Now finally, when you
are done scattering from starting to last position on
the divorce and fixed eddie, then this formula comes to n. That is, if you are done
scanning this whole expression, that is from the year two and then four loop
comes to the end. And that case, nastily have to check it's still if
your stack is not empty, you can see if your
stack is not empty, then you have to keep
on pumping and you have to keep on storing
in this prefix. Then finally, after
storing all the elements, after popping on the
lemon stronger stack, then you simply append it
with this null character. The last. Finally, you bought this
prefix fixed expression. Now student job
is not completed. You are left with one more task. Nowadays, expression which
you obtain after applying these rules and after repulping all elements
from the stack stuff, that expression that you get. Now again, you have to
reverse this expression. The expression which you
get after reversing. That will be the
final expression, which is the prefix expression. So I hope you want
to understanding. If you haven't already
seen on the whiteboard or the prefix you bought. Now again, I have used this
for you to simply reverse this fixed display,
fixed expression. So you can see again,
since actually the most I've been stored the
last element of this trip, etc, to the 0th position. So I have taken the new array
by the name reverse prefix. You can see here this added, which is this expression which I got better,
I will be storing. I'm not taking the new array. Yeah, I'm storing in this edit, so this is in fixed
to flip x I call from the main function by the
object in fixed expression. And I went fast, one added with the one which I was not filling in from
the main function. This adding I'm filling
this reverse, be fixed. I'm feeling I've
been restoring here. This is the one restored
in this reverse. So the final expression
which I get I will be storing in this
reverse perfect. So you and I will see you understanding what I'm
saying, this final prefix. Because after
reversing this prefix, then the result in which
I get that will be the one that we will
finally reversed. And so that is an easy
filling in this argument, which then use us as a character array that
was not filled audio. I hope so You bought funds, this is done, this is reversed. Find a new gets
reversed and fixed expedition after this for-loop and then you are appending
the null character. This is the final reverse
prefix expression. Let's move on to
the main function. Better. Thrombectomy was calling it. Now we have seen how to convert fixed or prefix me gotta result in
prefix expression. Now we're simply printing. This is a main function. Here. We're just calling this
functioning fixture pubic. So we got final conversion
stored in this prefix. We have simply printing. And then finally we have to evaluate this prefix expression. So again, by this object into P, I'm simply calling the function
eval underscore prefix. And this prefix, which is that there is a prefix
which I got you. Now, I will simply
call this function, and I'll pass this
prefix in this function. So what is the definition? Let's see here how to evaluate
the script X expression. This is the evaluation. So this is, you see here, this slight difference in this evaluation on
most everything is seen as compared to the
evaluation on the postfix, but little bit
differences there. Let's see that you'll
understand it more than Z because on most stone, same as compared to that of the evaluation
on the postfix. Like Little Italy difference. This evaluation of
prefix wherein the input will be the prefix
expression which we obtain. Here I'm simply displaying the message
evaluation of prefix. I'm taking these variables, we can see what is
the user on that. Now, if you see here, I'm taking the
for-loop beginning. What I will do the resultant. Let me move on here. First of all, this is prefix expression
which we obtain. I've been showing you when
we execute the program. So this is a prefix expression which means InDesign passing in this function that is irrelevant the school prefect so as to
evaluate this expression. Now, what will
happen in this case? So if you see here, I haven't taken the bottom loop, I will be scanning, but I will be scanning
from big name. So if you compare the data of the evaluation on the
postfix expression for earlier. If you've lost evaluating
from beginning to end. In case of the evaluation
of the prefix, we are not evaluating
from beginning to end. We're evaluating from big name. And that would require
knew I had started from Greenland trip x minus one. Then it will be you
can see here we