QUEUE IMPLEMENTATION USING LINKED LIST - DATA STRUCTURES

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello fans welcome back to our Channel so the previous session we have seen the implementation of stack using linkedlist so these stack and cubes linear structures can be implemented by using two ways that is one by using arrays another one by using the link artist so the main disadvantage of using arrays is static memory allocation that means so we need to specify the size of the array before starting the implementation and that can be avoided in implementing using this link released because here will be use the dynamic memory allocation so before inserting an element we will allocate a memory for that element and then we will start the implementation in this link addressed right now we will go to the queues using linker list right so we know that link release means loads so elements will be represented as a nodes and each node will be having two fields one is for storing the value another one is for storing the address of the next node right so first we need to specify the structure of a node and then we will go with the implementation and coming to the queue we we have seen the two operations on queues that is n Q and a D Q so here the NQ means inciting the element and D Q means deleting the element from the queue and the third operation that is a displaying the elements of it you right so coming to this enqueue and dequeue here there will be two ends one is a front end and other one is a Mainer so here the Q will follows the first-in first-out mechanism so first in first out so what are the element which is inserted first into the Q that that event should be removed first so for this purpose the all the insertions will be performed at the rear end and all the deletions will be performed at the front end so the best example for this Q is so standing on a line in the reservation counter right so all these things would have seen in the Q's implementation using errors right now we will go with the implementation first we will write the structure of a node and then we will go with the NQ n DQ using an equalist right so start node in data so to face that is in the data self-referential structures fact node star next star mu star and so all these are the different notes all these are the different notes so new will be having their tile next rail will be having a tire next front will be having data and next M will be having data analyst so these are all the structures right structure variables now we will go to the entry operations that is friend I mean nqn deep-sea so cue representation is in this way huge presentation is in this way so this is the friend this is the rail okay so initially initially friend and rain will be friend is equal to red is equal to none so after inserting a little bit we required to increment the name and then we have to increment and in we have inserted element okay so friends will always points to the starting position of the cue start an element of the cue rain will point the end position that means our last element of the cube now we will go to the NGO operation when you go to the NGO operation and cue and humans inserting an element into the queue so first in order to insert an element first we need to allocate the memory for that node and then we will read the element and then inside so first the noodle is equal to analog right so this statement will allocate a memory to the new then hidden element scanf percentage team some ampersand element now we have to insert this element into the data value data field and in the next field we have to store the address of the next element so as this is the first element if sorry if this is the first element in the queue then the next field will not having the address of the next next node so that's why it should be filled with mother so initial if it is an initial element if it is initial in right so before that we'll check for whether this is an initial element of Nos so initially this rail is equal to null friend is equal to null initially where is equal to null front is equal to null so if so if it is a first element in the queue then friend or rare so any anything we can write say and then is equal to is equal to null so before seeing the condition we can simply write a new of data is equal to element new of next is equal to null then check for tradition whether this is a first element at the queue or not so if it is a first and main so how can we know that it is a first element so simply and when is equal T is equal to null if red is equal to is equal to null that implies it is a first element because there should be updated for every insertion then simply we can update the red friend friend so friend is equal to dual-rail is equal to new else so so if you are inserting an element first memory will be allocated so in or will be created here both will be created here so scanner filament if you ready to tell new york theta is equal to 10 so 10 will be updated here new off next equal to null and that will be a billion here and then if red light is equal to 3 is equal to null yes here also this windy fact is equal to nuclear is equal to new so friend and red if you are implementing again this l2 operation if you are again implementing the NQ operation the second event should be inserted and same thing new so other mode is created here and the road is created here and if the second element is 20 right and no octet is equal to the element quantity you know next equal to null York next equal to null is placing here if red is equal to is equal to null know if front end array is having the enters of M so this fatty shall Falls yes but will be executed what should be done here now the thing should be established between first one and second one so how the rail of next so in this it should store the address of 20 so rare of mixed we're off next is equal to MU so odd obviously this is a 2000 lady this is a thousand degree so this love will be replaced mid 2000 so a link will be established now a bit of trail because every insertion will be done at the radiant rare is equal to mu so this rain will be updated to here hope you understood again if you are inserting the third element 30 so there will be one more norm is created so your theta 30 will be here and York next null will be here so if rare is equal to null false friend so else part will be excuted we're off next so they're off next so this field this field will be filled with in you solid will be 3000 so 3,000 will be placed here so automatically a connection is established here and rain is equal to you so rare is equal to they are going to be pointing here right so hope you are some bully for the first element we have to change the front end rain for after that for every insertion or every NQ operation we need to update the rail because the instructions will be done at the rain so this is all about this NQ operation so hope you understood this one now we move on to the next operation that is did you that means a deletion so deletion will be done at the front end did you that is decision will be done at the friendly see let us take three words in a queue some ten twenty thirty two thousand three thousand morrow so this is the friend this is the rate so thousand here address right now let's implement the DQ that means we have to delete a little bit from the front end that is ten should be deleted now if you want to delete the ten first we have to check whether the queue is empty or not then the queue will be empty well the queue will be empty if the front is equal to null because we are deleting the element from the friend so if friend is equal to is equal to null if the friend is equal to is equal to null that implies the queue is empty so we can simply write printf queue is empty right yes yes if K is not empty now if we need to remove this friend now for this simply assign this friend to some temporary where you assign this friend to some temporary value now move that friend to the next table because the first elements will be deleted so friend is equal to friend off next so after implementing this one friend of next that means friend is point into the this one right no we need to change this one delete this one so we can place and money in place of the address field so that then the traction will be disconnected or simply we can use the free function so in the dynamic memory allocation we had another function called a free function which will clear all the memory which is allocated by using the metaphor here Kellog functions right so we can use anything now here am visible friend here temp is pointing the first element temp is equal to friend every spawned into the first element now we can remove this one so either we can use M of next equal to null automatically this will be removed and what we do will be place it here so that connection will be disconnected the connection will be discarded or simply we can use free o and free of temp that means all the memory which is allocated for this load that will be removed clear the memory will be cleared right so this is the simple logic for deleting an element C after deleting this one the front piece 20 and then is 30 so if you are again applying this DQ this one here also will be deleted friends will be moving here okay so hope you understood this one right so this is called the DQ that means deleting an element so insertions will be done at the range and deletions will be done at the front end now helm or to the path third one that is display how to display the image of a queue hey we go with that display function so display so here we need to start from the franc and we have to move to the Tilda way so simply we can use here first we will let us check whether the queue is empty or not so we know that you want to check that a queue is empty or not check the friend is equal to is equal to null so if this condition satisfies simply we can display Q is and B yes yes starting from the front display all the elements so until my friend not equal to so here in order to travel from the first to first not the last word just use the temporary just use the temporary when temp not equal to null temp not equal to none right so we need no we should not change the friend friend value so that's why we are just assigning the friend to the temporary variable pepper available and then we have traveling through heparin variable so here c3 their percentage temp of data so every value will be printed here and after printing the value we need to update them so M easy I'm off next that's it sympathy so if you trace this one see em is equal to friend so M is also assigning to the same room friend is equal to is equal to none so initially the friend is equal to thousand so from this is pulse how do we get it here it will be gone so M is equal to M not equal to null so here again MV is equal to thousand because temp is equal to friend so can not equal to love condition - right here right here temp not equal to null condition is true temp of data temp of data means M so 10 will be printed here temp is equal to temp of the next now F is equal to M of next image mm mm automatically this temp will be pointing to mm again tell not equal to null I am hot equal to no.2 condition is true so printf type of data 20 will be printed here right then temp is equal to type of the next so temp is equal to temp of next that mean 3000 again the temp will be pointing at the 2000 now again simple M not equal to null condition is true because Catholics 43,000 here so temp of data 30 will be dreaded temp is equal to type of things so here M is equal to temp of next that is null right again loop temporada call - no M not equal to null here the condition fails here recognition fails so automatically it comes out from the loop and it exits the display function so this is how we can display the elements of it q which is used implementing this linkedlist right so hope you understood this display operation also simple things so if you understood the linkedlist concept and all the remaining concepts will be very simple so my suggestion is before going to the stack and queues so just go through the link list and then you can implement this stack and queues in a simple way right so let us stop here and if you are having any doubts regarding today's session feel free to post your thoughts in the comment section so that I will definitely try to clarify all your don'ts and if you really notice from my sessions like my sessions share my sessions with your friends and don't forget to subscribe to our channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 37,717
Rating: undefined out of 5
Keywords: sundeep, saradhi, kanthety, data structures, fundamentals, basics, arrays, lists, linked lists, stacks, queues, trees, graphs, searching, sorting, insertion, deletion, operations on data structures, primitive, non primitive, linear, non linear, binary trees, binary search trees, display, overflow, underflow, index, array size, LINKED LIST, dynamic memory, malloc, free, QUEUE USING LINKED LIST, enqueue, dequeue, queue display, queue empty, queue using arrays, FIFO, FIRST IN FIRST OUT
Id: QfRoQMSJ664
Channel Id: undefined
Length: 21min 26sec (1286 seconds)
Published: Fri Jun 14 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.