How to Implement a Queue in C

  Рет қаралды 67,550

Jacob Sorber

Jacob Sorber

Күн бұрын

Пікірлер: 71
@mikerowaveoven509
@mikerowaveoven509 4 жыл бұрын
Love the sound of the keyboard in the background :D
@tastypie2276
@tastypie2276 3 жыл бұрын
You are helping me so much with studying. I hope I will reach the level when I'm able to create a soft that likes videos automatically. Then I will launch it and set it to like all of your videos!
@y-yyy
@y-yyy 2 жыл бұрын
Thank you so much! Love your explanation of the code, very eloquent and clear.
@procyte2139
@procyte2139 4 жыл бұрын
Really interesting videos! I really like it. I think the next step-up for your channel would be to improved visuals like 2D animations. Then this would be a incredible channel.
@JacobSorber
@JacobSorber 4 жыл бұрын
Thanks, and I completely agree. It's always just an issue of how much time I can put into each video. Sometimes there's a little extra time for animation. Sometimes there's not.
@alexbright5140
@alexbright5140 2 жыл бұрын
we definitely don't want our tail dangling there 😂 5:40 AMAZING CONTENTS
@dusanmalusev9530
@dusanmalusev9530 4 жыл бұрын
Wow, such a good video, maybe you can do a follow up on thread safe queue, i wish i have teachers like you in my university
@JacobSorber
@JacobSorber 4 жыл бұрын
Thanks, Dusan. I'll keep it on the list. In the meantime, I hit close to that topic in my thread safety video (the bacon one) and in one of my multithreaded webserver videos.
@fallofmanbrand
@fallofmanbrand 4 жыл бұрын
Loved It!
@marcelijankowski9593
@marcelijankowski9593 3 жыл бұрын
I Love Your explanations
@vichnykh
@vichnykh 3 жыл бұрын
Really nice lesson, thank you so much!
@kubic-c3186
@kubic-c3186 3 жыл бұрын
you could instead use a memory pool instead of malloc, and then resize it every time you ran out of space(if enqueue is called more the dequeue)
@tails_the_god
@tails_the_god 2 жыл бұрын
Thanks! Great tutorial!
@karimkohel3240
@karimkohel3240 4 жыл бұрын
YES MORE DATA STRUCTERS
@GlobalYoung7
@GlobalYoung7 2 жыл бұрын
thank you 👍
@karimkohel3240
@karimkohel3240 4 жыл бұрын
Patiently waiting for the graph video
@JacobSorber
@JacobSorber 4 жыл бұрын
I know. Thanks for your patience. Also, are you more interested in adjacency matrix or adjacency list-style graphs? I might have time to do both, but figured I would ask just in case.
@karimkohel3240
@karimkohel3240 4 жыл бұрын
@@JacobSorber i don't know what that means so it would be awesome if we started at that point XD
@atkuriajaykumar3701
@atkuriajaykumar3701 4 жыл бұрын
Jacob which videos I should watch to understand this better I understood theoretical part well.
@notyetdecided
@notyetdecided 4 жыл бұрын
thanks
@opensourcemundo3415
@opensourcemundo3415 3 жыл бұрын
Amazing video, I just don't get one thing: why do we save the head in a tmp to obtain the result? Wouldn't it be the same if I just did "int result = q->head->value" ?
@JacobSorber
@JacobSorber 3 жыл бұрын
Thanks. Yes, you can definitely do that. Saving the pointer is just so you can free it, after you remove it from the queue. Whether you get the result from the temporary pointer or from q->head, doesn't matter.
@HasanBasri-vf2kg
@HasanBasri-vf2kg 4 жыл бұрын
Dear teacher. Thanks a lot for your effort and videos. Can you take a video about semaphores, mutexes? Greetings from Turkey, İzmir👋
@enestastan7147
@enestastan7147 4 жыл бұрын
You can check this video of him: kzbin.info/www/bejne/b5Lbpmt5ituCgbs I don’t know if that covers all the things you are curious about.
@JacobSorber
@JacobSorber 4 жыл бұрын
Thanks, Enes.
@mohammedtajir2276
@mohammedtajir2276 3 ай бұрын
bro i forgot to concentrate on concept in that good background music of keyboard :)
@furball_vixie
@furball_vixie 4 жыл бұрын
i love these videos, will you be doing more data structures?
@JacobSorber
@JacobSorber 4 жыл бұрын
Thanks. Yes, I've got a few more on the plan for the coming weeks/months. Hoping to get to trees and queues, and hopefully some fancier structures after that.
@ChocolateMilkCultLeader
@ChocolateMilkCultLeader 4 жыл бұрын
I wish I had this last year
@JacobSorber
@JacobSorber 4 жыл бұрын
Me too.
@windowsbuilderthegreat3121
@windowsbuilderthegreat3121 Жыл бұрын
When looking at your enqueue function, it looks like it can cause a memory leak. wouldn’t it be better to dereference the value into that in the node and then free the pointer after finishing with it?
@nassar_productions
@nassar_productions 4 жыл бұрын
Hello, if I created.a queue, the enqueue function has a malloc allocation, so I want to deallocate it before exiting using free(). But I can't seem to properly and successfully deallocate that? any suggestions?
@JacobSorber
@JacobSorber 4 жыл бұрын
There's not enough info here to know what's going on, but I would recommend freeing the memory (the same address you got from malloc-you can use your debugger to make sure you're doing that) after you dequeue the nodes from the list.
@nassar_productions
@nassar_productions 4 жыл бұрын
Yes, I figured out that freeing the head in dequeue function does the trick. Thanks !
@HuynhCongToaiK18HCM
@HuynhCongToaiK18HCM Жыл бұрын
hi, I have a question, in this specific scenario, can we replace 'q->tail = newNode' (line 36) with 'q->tail = q->tail->next' as an alternative? (because we've already assigned q->tail->next to newNode)
@MA-ek1xl
@MA-ek1xl 2 жыл бұрын
I wasn't able to get the code to work actually. could you post them in a link in the description?
@JosephKlem1
@JosephKlem1 2 жыл бұрын
This was super helpful, thanks, Jacob. One question: was QUEUE_EMPTY declared somewhere as an int constant? The dequeue function is supposed to return an int, so I wasn't sure how it could return something called QUEUE_EMPTY unless that somehow carried an int value. Can you explain? Thanks.
@matty2128
@matty2128 2 жыл бұрын
Most likely he set an int constant somewhere else that signifies an empty result. So early on he could have done something similar to define QUEUE_EMPTY -1. He could then have a return if statement that checks the result of what is being returned. That being said an int is still being returned.
@mariusel9916
@mariusel9916 Жыл бұрын
it was defined in the stack video as #define QUEUE_EMPTY INT_MIN... but for this you'll need
@chimichanga7033
@chimichanga7033 4 жыл бұрын
So we are not technically removing a number from a queue its still there just moving the pointer head to the next one and printing the number on the screen, right?
@janruui5506
@janruui5506 4 жыл бұрын
You are the best thank you very much I love your Videos👍👍👍👍👍👍👍👍👍 Can you make a Video and explaine this kind of code in C: int (*ptr) (int, int) = &function; And this int *ptr[10]; int (*ptrr) [10]; We had this in the lecture but I don't understand for what we use this
@JacobSorber
@JacobSorber 4 жыл бұрын
Thanks. You might want to check out my videos on function pointers, double pointers, and the relationship between pointers and arrays. Might help here.
@janruui5506
@janruui5506 4 жыл бұрын
@@JacobSorber thank you👍
@csbnikhil
@csbnikhil 4 жыл бұрын
​@@janruui5506 You can check out Demystifying Pointers - Function Pointers, by @theteachr for an animated version.
@devilminty_fresh
@devilminty_fresh 4 жыл бұрын
Hey! Can you show us how you would implement a priority queue?
@cassiewinger7041
@cassiewinger7041 4 жыл бұрын
Priority queues are implemented using heaps (max heaps and min heaps). u gotta learn heaps first, just take a look at the wikipedia page, it'll take up to 10 mins good luck
@cassiewinger7041
@cassiewinger7041 4 жыл бұрын
awesome videos, as always thanks can you make a tutorial on how linkers work? and/or introduce some references/documents or whatever? thank you so much
@JacobSorber
@JacobSorber 4 жыл бұрын
Thanks. Great suggestion. Do you have a specific linker question, because it's a pretty significant topic.
@cassiewinger7041
@cassiewinger7041 4 жыл бұрын
​@@JacobSorber if you could explain the general structure/internals of object files and how linker combines object files, it'd be really great. 'cause i looked for tutorials and resources on these topics, didn't find any. make a few tutorials structure of object files and how linker combines object files. PLEASE. thanks
@cassiewinger7041
@cassiewinger7041 4 жыл бұрын
@@JacobSorber I don't generally know how linkers work myself. If you could just make one or two tutorials and point the way so I/we can learn linkers better, it'd really really great. THANKS
@JacobSorber
@JacobSorber 4 жыл бұрын
@@cassiewinger7041 Ok. I'll add it to the list and see what I can do.
@cassiewinger7041
@cassiewinger7041 4 жыл бұрын
@@JacobSorber thanks a lot. can't wait
@swallace21
@swallace21 Жыл бұрын
great video, the typing is super loud thought, really hard to hear your voice when there is typing
@randomman5280
@randomman5280 4 жыл бұрын
Hello Jacob, i hope you are healthy and safe too. I am a student and I am working on a project in which I am integrating Python code in C / C ++. There is the Cython tool that I use to generate C code so far everything is fine. The problem: The generated .c file "ther is no .h" cannot be learned at all. maybe you know how to generate a library from .c files only and also how to use them? I thank you in advance. greetings from Syria Kamil Alsaleh Alkhalil P.S. I rediscovered your channel. it's pretty helpful.
@JacobSorber
@JacobSorber 4 жыл бұрын
Hi Kamil. Thanks and welcome. I'll put cython on the topic list for future videos. In the meantime, I do have a few videos about libraries. They might be able to help.
@csbnikhil
@csbnikhil 4 жыл бұрын
The last few lines for enqueing are only useful for the first insertion. It's going to be wasteful until the list gets empty again. Is there a better way to achieve it?
@JacobSorber
@JacobSorber 4 жыл бұрын
You could combine the two if statement blocks. That might help a little. In the end, though, the cost of this check will be really small compared to the malloc call. So, I'm not sure whether it's worth worrying about.
@gauravshinde6306
@gauravshinde6306 4 жыл бұрын
Can u do a vid in vectors in cpp
@JacobSorber
@JacobSorber 4 жыл бұрын
Probably. Do you have a specific question about them, or just looking for a general overview of how they work and how to use them?
@gauravshinde6306
@gauravshinde6306 4 жыл бұрын
@@JacobSorber A general overview of them would be great as well as their applications. I know java linked lists look similar but I think everyone would like to know their applications
@HasanBasri-vf2kg
@HasanBasri-vf2kg 4 жыл бұрын
@@JacobSorber Sir I think in channel less videos about C++ than C. Can you take tutorial videos important topics in C++? Like as friend ask, why do we need STL? Are these things advantageous or not than using own your own data structures?
@franciscrypto9143
@franciscrypto9143 2 жыл бұрын
where is the source of code of this code?
@AngryGamer-RC_Maniac
@AngryGamer-RC_Maniac 4 жыл бұрын
You could have made this video far more easier mate, but you choosed a complex way with multiple typedefs which led to unnecessary notations as '->'.
@JacobSorber
@JacobSorber 4 жыл бұрын
Sweet. I opened up an opportunity for you to make a simpler one. 😀
@yusraazrademirel2195
@yusraazrademirel2195 2 жыл бұрын
why cant i understand :(((
@ajmaln2387
@ajmaln2387 2 жыл бұрын
ELEC 278 moment
@wocannaseilai5983
@wocannaseilai5983 4 жыл бұрын
Seco d
@robertcarmona5142
@robertcarmona5142 2 жыл бұрын
was about to follow along but all my professors have told me real programmers don't use Global variables.... really bad practice
@rustycherkas8229
@rustycherkas8229 2 жыл бұрын
Pity you didn't pay attention or stick around. NO(!) "Global" vars were used or abused in this video...
@14k46
@14k46 6 ай бұрын
over complicated!
How to Implement a Tree in C
14:39
Jacob Sorber
Рет қаралды 106 М.
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН
How to Implement a Stack in C (+ encapsulation)
15:38
Jacob Sorber
Рет қаралды 62 М.
Understanding and implementing a Hash Table (in C)
24:54
Jacob Sorber
Рет қаралды 377 М.
wtf is “the stack” ?
8:03
Low Level
Рет қаралды 129 М.
How do I access a single bit?
11:07
Jacob Sorber
Рет қаралды 23 М.
you will never ask about pointers again after watching this video
8:03
Understanding and implementing a Linked List in C and Java
18:15
Jacob Sorber
Рет қаралды 255 М.
8 Data Structures Every Programmer Should Know
17:09
ForrestKnight
Рет қаралды 275 М.
Data Structures, Explained Simply
30:34
Nic Barker
Рет қаралды 15 М.
Fixed and Variable Length Arrays in C and C++
20:24
Jacob Sorber
Рет қаралды 46 М.