Queue in Data Structure

I will one welcome to Naresh Technologies resistance in the last session we discussed completely a theoretical approach of a queue implementation now in the session will see how to perform operations on queue operations means how to insert an element into queue how to delete an element from the queue and how to travel all the elements again see here here it is queue implementation queue implementation using static arrays heading is queue implementation using static analysis statical is means what the fixed in size to size is a fixed size will not change so that is what we called a static carrot how to implement first declaration of a queue is very very important and declaration of queue size is a fixed size I was here here it is I am declaring one can’t into the size is a 5 or more clearly if you want to write with the help of preprocessor directive has defined as define the capacity capacity is a v net capacity we are writing here capacity that is decoration globally you have to declare a variable so then it will get memory allocation with the size is a v so we can insert five elements maximum because here it is a sizes of exercise and next one two variables we have to declare so what are the variables means if you want to insert are if you want to delete mostly queue operations we need to perform operations we need to perform with the help of two variables front and rear because insertion of elements into the cube is possible through rain and next one deletion is possible through front light physically we can say that right from the rear we are inserting the elements into the queue and from the front we are deleting the elements from the equipment programmatically how can we show by declaring variables only so here we are declaring two variables one is a tint friend = 20 and next one in a rare = 20 in front = 20 and intra = 0 initially front and rear both are Pointing location 0 and 0 ok and remember whenever front and rear is equals to zero so that is what we called queue is empty we are not inserting any elements at so initially here it is it is Pointing where is also Pointing irrigation insertion operation and deletion operation and next one display operation observe the size of 12345 and index index initially the front value front value is 80 and rear value is zero now all the three functions am writing side-by-side here it is for insert function how to insert an element into the queue insert function second one is a how to delete an element from the queue delete and next one how to traverse elements travis is nothing but displaying the elements of total three functions all the three will discuss so first of all if you want to insert the elements insert and delete both are we are writing suppose if you want to insert elements into the cube we need to check queue is full or not for insertion because if he is already full you cannot insert the elements in the same way suppose if you want to delete the elements then we need to check queue is empty or not because if queue is empty we cannot delete the elements from the queue ok see here it is we are checking if if on some condition to declare local variables live some space is based on some condition we don’t know condition as of now here it is a printer printer queue is full the situation will come but when it will come we don’t know that will see but we are writing the condition as we are inserting the elements in the same way in case of deletion also if if now on some condition we need to check printer queue is empty so you cannot perform a deletion operation on the queue we cannot perform division operation because please him 3 no element is there to delete sir when sir whenever front value is equals to rain because front = 20 and l = 20 right so then simply here we are writing queue is empty whenever front equals to rear queue is empty queue is empty and next one in case of a Travis also I want to display the elements same story first we need to check right Q contains elements or not if no elements simply we are printing queue is empty queue is empty this is write insert delete a Travels but here sir what is the condition that you will understand slowly in the else part as parts opposite space is there initially front is pointing to andrea is also Pointing location front and rear now I want to insert the elements asking here it is suppose we are declaring one variable element is read that element directly I’m writing actually here we have to write a print of hand scanner right we are reading that element after reading that element we need to insert we need to insert that element into this location for which variable we have to use Saffron it is also pointing to the where is also Pointing which variable we can use can I use a friend know that all the operations from read only variable array variable only you have to use so here that element whatever the element you read that will be stored into of rare that will be stored into queue of rare because Kyun is pointing to element supports 10 consider that will be stored into rear rear value is 80 na yes so that will be stored here after that we should move the rear position to insert the next element here simply where value is increased by 1 rare plus plus this is simply insertion insert one more element in set 1 more element then what will happen so very simple again insert function will call if condition later because some more elements are there and read values of an increased now where is Pointing location nothing but first index number second location now we are reading the element using printf and scanf function next element will be collected into queue of rare of rare means what now this is a location makes the real value will be increased fair value become too next where is pointing to location third element insertion and here it is it will store 30 nexa rear value become three next Re. Location next element insertion 40 rare value become 4 next film insertion where is Pointing location shift elements and the rear become 5 hair become file whenever there is a file where is Pointing station which is not present read values of 5 successful whenever rare value is equals to 55 is nothing water capacity whenever there is equals to capacity capacity of a cube of the cube so then we can say that to is fully can say that who is full this is simply insertion condition we can keep on inserting so finally write the real value is equals to the capacity by that time if block will execute not else block because there is no place to insert the next element Sixth Element aerospace inserting an element into the queue so finally read value is a v array value is a file now there is no option to insert so we are deleting just considered deleting or we can display also so fast wheelchair Travels Travels very simple if you want to display all the elements first we have to check elements are present or not elements are present or not we have to check I was here it is different is equals to Re we already discuss that if both are equal right in the initial stage whenever you start whenever you declare the variables by the time front value and read value both are same why the time no elements inside the view that we can say that Q is a empty now in the else block we are displaying all the elements displaying and here it is we are just giving the message print SQL immensa Kyun elements so many elements will be present then how can we print just use the for loop I value starts with 0 from the first location or more clearly from the front location because friend is always. In erode location friend is lesbian Re not less than or equal Store service opposite is elements upto 4th location where is pointing to so we cannot access the element which is inside the rear location for less than rail UPTU here so less than rare and I + + + + we are printing the elements printer percentage De fashion and here it is simply Kyun of eye the value year printing simple we should move right so we should travel or simply we should iterate from first location to nothing but from front location to less than relocation how many elements are there all the elements we are displaying simple thing this is how to display the elements directly you can’t first you have to check write the queue is empty or not if queue is empty you can’t perform any operation mainly we can’t display the elements which are inside the Q now the last operation is it deletion operation solution for example if front is equals to rear view is empty by the time you can’t delete or else or else so what we have to performance first directly we are deleting this element we are deleting 10 year printing deleted item is percentage De that is Q of friend that is true of friend so what is the cube of friend to value quiz pointing to next Aqua front means front is 80920 front always Pointing we can’t disturb the location right front variable no need to disturb from starting to ending it is always pointing to location only location deletion it is impossible to delete the information we have to overwrite the information that is after saying that deleted that value 10 next what we have to do means we need to shift all the elements we need to shift all the elements how to shift same story using for loop using for loop we should start from the first location first location means what from front plus one location here it is here it is a value starts from 1 days less than how many locations simply less than rear less than Red Eye plus plus plus plus then how can we shift simply Q of few of my value will be storage into queue of I – 1 iMO clearly can I start with zero only then no problem then QR 5 + 1 value will be stored in to cure of eye kyun of I saw that means this is Q that means I was initially I value 0 0 + 1 means what one the one value will be story in 200 that is a 22 shifted to hear 20 next I value will increase I value become one here it is one is less than re read values of 5 and next 15 + 15 + 1 value means what 1 + 1 is it 212 will be open party will come to here cutting right next I value become 23 value will come to here for the next I value 450 come to here 50 so come to here next I value 5 sorry I value for but here it is a for is less than read value V Na so whenever we are writing like this this location will come to hear this value because already 15 shifted no need to save this 124 only less than rare right here is a real value 5 so this is less than 3 – 1 train -1 is less than 4 conditions Falls because no need to shift the element 50 simple thing then what we have to do very simple finally where values of 51 element deleted means rear value should be decreased by one where is not pointing to the rare should. Into location simply what we have to write Re minus mai simple after insertion rear plus plus after deletion rear minus minus and very very important concept this follow shifting of elements very very important generally the people saying that after deleting the element from the front they will move the front value impossible we should not supposed to move the front value we should not supposed to move the front value then what we have to do what we have to do means always we have to shift the elements from first location to relocation all the elements we have to shift by one locations towards the forward direction right words forward Direction this is how to perform insertion operation deletion operations and travels operation in queue against this is all about abstract data type or queue in data structure abstract data type for queue Data Structure ok all the operations how to perform the complete explain nation about queue Data Structure ok thank you thank you for watching for more videos please subscribe to Naresh additional thank you

Speak Your Mind