ARRAY - Making DATA STRUCTURES in C++
Vložit
- čas přidán 16. 07. 2020
- The first 1000 people who click the link will get 2 free months of Skillshare Premium: skl.sh/thechernoproject10
Patreon ► / thecherno
Instagram ► / thecherno
Twitter ► / thecherno
Discord ► thecherno.com/discord
Series Playlist ► thecherno.com/cpp
This video was sponsored by Skillshare.
Thanks for watching! Don't forget that the first 1000 people who click the link will get 2 free months of Skillshare Premium: skl.sh/thechernoproject10
Watched your all C++ vidoes.. those are awesome.. thanks for this video waiting for STL from long time
Damn I cannot take it.
Not able to sign up
Just wanna say thank you so much for the Skillshare offer.
Can't wait to study more programming and game design! :D
Thanks for this, I've been wanting to try it! Got in on it!
Suggestion: video on CMAKE, makefiles, etc
YES PLEASE
Somebody asks that on almost every one of those videos and I’m pretty sure the reason he hasn’t done a video on the subject is because Makefiles, etc., aren’t part of the C++ language, and this is a C++ language tutorial. Plus, he uses visual studio, which doesn’t use Makefiles, so it would be pointless.
@@jscorpio1987 you could say it's a null pointer
He doesnt even use cmake and makefile is not usefull to him since he uses windows+vstudio only
Those are poor excuses for not doing it. Plenty of projects that use C++ make use of cmake or make files. He probably runs into them quite a bit, especially with open source projects.
Waiting for data structures for a looooong time super excited for this series
Suggestion: linked lists then binary trees.
My knowledge of this area is a little patchy and hearing a second expert explanation of a topic is always welcome.
cool
I agree with this order, binary trees are in of themselves a linked list. Hopefully he'll explain doubly, single, and circular linked lists sometime soon.
@@nallid7357 Not all. You can implement binary heap with an array.
Definitely need video on implementing iterator please
A really super simple forward iterator is literally just a pointer. So part of your goal is already done.
@@jamesmnguyen Yeah, but that only works for two data structures, vector and array, and the latter works because arrays decay into pointers. Implementing iterators for anything else is more complicated.
@@oracleoftroy Iterators for linked lists are also pretty easy. It gets harder for trees though, because you need to figure out the logic to access every element in the right order. Especially if it is a search tree, where the order is important
@@maksymiliank5135 ... which is indeed one good reason to look forward for a tutorial from The Cherno. That promises to be quite exciting.
Love raw breakdowns like this. This quality is what makes your channel unique 👍
Awesome man! Very glad you opted to start delving into data structures and algorithms in your C++ vids! Very much looking forward to more of these! Thanks so much.
I'm glad you're doing this series lmao. I took a data structures course at my university last year, and now I can keep myself refreshed on the material through these videos so I don't forget all these concepts
I've wanted to this exact thing for a long time and was never able to fit the pieces together. Thank you. :D
i love you for doing this. 1 BIG recommedation is to move this videos to early parts of the playlist. many thanks. love your work!
That "noise" at the top is very useful. It allows you to write things like using container = std::array; container x; memset(x.data(), 0, x.size() * sizeof(container::value_type));
Then when you need to change int to uint64_t or uint8_t, you only need to change it in one place. Putting sizeof(int) in that memset is buffer overflow waiting to happen.
Thanks for this series. The stack and heap allocation just made me smile.
This series is super helpfull! :)
Edit: Also, the way Cherno explains the things (dissected and explained step by step, from basic functionality too the more complex results) is so much better then most written documentation you can find..
I was waiting soo eagerly for this 🙏🏼 your videos have become my bread butter daily these days haha.
Thanks so much for sharing all your knowledge cherno!
Love this data structure focused video in the C++ series. Please keep the coming!
Thank you So Much , you are the best channel i've seen ... you are beyond professional. You are my inspiration in learning c++ and, i hope you keep making videos, love you Cherno.
Simply brilliant, Cherno! Keep them coming!
Could you do a video on ideas for projects beginners/intermediate C++ programmers could do to add on to their resume? Currently going into my 3rd year in college, and I'm looking to apply for internships for next summer, but I don't really have any projects to put on my resume nor do I know where to start.
How is it going
Thank you so much ! Looking forward for the iteraror implementation. Also, I'd like to see you talk about boost library, more specifically boost::bind methods (also also, I believe they have been integrated into STD by now)
Waited for this for so long! Looking forward.
I'm really gonna LOVE this! I was always trying to implement different STL classes that I use and love myself. And also to expand and add upon them. My favourite ones were String and List(dynamic array).
Thanks a lot for your great content Yan 💙💙
std::list is not a dynamic array ;)
Love this style where the video zooms in on the code and it is easier to see.👍
My very favourite topic in C++ : data structures. Thank you so looking forward to it.
Thank you Cherno! was helpful as always.
Definitely gave me more insight regarding OOP and templates!
glad you're making data structs & algos series.
would also be good to mention using arrays unless you need optimization is bad practice, and more generally optimizing before you need to. and it would be nice if you go into some of the nitty gritty details about why there's an overhead from not keeping your data contiguous; it's not self evident, and especially mysterious if you know your programs use virtual memory.
Loved your videos. Learning so much.
This was so helpful! Thanks
Awesome! Can't wait to see the next DS 😍
Would love it if you would do more of these!
Thank you so much 🙂. What a great series of c++..
Would love to see videos implementing data structures of other STL containers like vectors and strings with things such as iterators within them in the future. Anyway, great video :)
Thanks, Cherno! Your channel is a real treasure)
best cover of data structure. Thanks for sharing
Yes more of this please
I found this very useful, thank you!
Great Video! I just made a dynamic array and a doubly linked list last semester. It is so much harder than it oringinally sounded. Would love to see how to create a (un)ordered (multi)map or a priority tree of some sort! Thanks again! :)
Thank you Cherno. Admire your work.
Great refresher!!!♡☆
Suggestion: templated version of segment tree.
I know it's not that important but if you find time, it'll be pretty interesting to do.
Live demos are cool! Hopefully I will see you on some gamedev/cpp conference as a speaker.
Nice, would be lovely to see you cover tree-based data structures. probably after linked lists.
Great videos!!!
Could you make a video about UNIT TESTs in C++?
up
Yes please!
The content....Love it 🔥
Thank you
thanks for the explanation😊
You are running through the material so fast, you cannot be teaching. You are not teaching what you are talking about but running through the material demonstrating how well you know it. But, for someone trying to learn, it all flies over my head.
Great Great Great! video. What a great video to watch while drinking my morning coffee ;)
AVL trees intrigue me and I'd love to see them in a future video
Nice video as always ^^
I'd like to see some implementation of Dictionaries and maybe showing that with hash functions. I only understand that they are probably used for that, but I wonder how you actually use them effective. Wondering how much space to allocate and still use hashes.
I dislike all those who hit the dislike button. Thanks for that beautiful lesson Cherno!
Honestly, I did not touch c++ since 3rd year at uni. This video made ne remember a lot about c++ and tought me more about it than 2 hours at uni ever did)
Def subscribed coaus of that. Even though I don't use c++ at work)
In case you need it, here is the source code of the array data structure:
#include
#include
template
class Array{
public:
constexpr size_t Size() const {
return S;
}
T& operator[](size_t index){
return m_Data[index];
}
const T& operator[](size_t index) const{
return m_Data[index];
}
T* Data(){
return m_Data;
}
const T* Data() const {
return m_Data;
}
private:
T m_Data[S];
};
int main(){
Array data;
data[0] = "Cherno";
data[1] = "C++";
data[2] = "We";
data[3] = "Love";
data[4] = "Programming!";
for(size_t i = 0; i
I'd love to see a simple compiler series using flex and bison to generate a abstract syntax tree that is class based. Then see it in action. An AST that can be reused in other languages you work on.
Cherno this C++ series is legendary
A few remarks
The STL array has its underlying array field public to allow for aggregate initialization, like you can do with a plain array.
All the type members like pointer, const_iterator, etc. are actually required by the standard, not just in MSVC implementation
I am an undergraduate student. I already love your content and find it really inspiring. But can you please do more content related to basics and Data Structures?
Waiting for this
That is exactly what i want to learn.
People, never ever in a million years do a memset call like was shown in this video. That is allowing external code to operate in the private parts of the class. Place the memory setting code INSIDE the class. That code there I would have marked as needs work if I ever saw it in a pull request.
Thanks again
FINALLY!! I've been waiting for a DATA STRUCTURES series for what feels like ages. Much appreciated!!
dude you are a god
thanks for the video
you know , I had sworn that I will never understand loops but after watching your video on the topic , I am on the safe side now, I guess, Thanks man....
More videos like this pls pls!!!!!!!!!
nice & usefull video
Exception handling, and whether or not to use them please :)
Great video! Suggestion: I would really like to know what constexpr and noexcept are...
Very good content as always. In one of the first videos (video 2 of C++ Series) I downloaded your vs settings. They seems to have changed. Do you update the link or give a one with your updated settings?
Cherno, can you please make a video to explain the difference between constexpr and const ? Thank you ...
While arrays may be easy to deal with, I would certainly like to see you implement some much more complex types like tuple. XD
Also, those size_type things are required by the standard, so that template meta-programming on std containers is easier.
std::array are implemented as a struct containing a public member of the array, which makes the struct an aggregate, that enables the aggregate initialization syntax (like std::array array{ 0,1,2,3,4 };) without requiring any constructor to be implemented manually.
How is a tuple complex?
@@sebastiangudino9377 Try implement a tuple type yourself and you'll see.
The problem I had with these types of structures is that it becomes annoying to pass the arrays around in functions. since Array is a completely different type than Array unless there's some magical c++ way to do it...
Careful with alloca(), it is non-standard (even in C) I think it's only standardized by POSIX, which makes sense because Microsoft's version easily breaks in try/catch blocks. alloca() does have its uses, but if you can get away with a stack array or a SmallVector, you probably want to use that instead.
Great!!!
Looking forward to Cherno making his own mini-stl
the::cherno::libs::standard::stl
Awesome
WE WANT MORE DATA STRUCT VIDEOS les goo
Wow continue doing data structure please
Please cover unit tests and tuples implementation.
hi bro can u start the data structures and mainly algorithm series if u have time.im eagerly looking for that series. or can u point where i can learn those concepts really good.
Great, no 2-minute long intro that has nothing to do with the video, great!
The alloca has a larger issue there. Unrelated to performance. The problem is that it will be freed after the constructor retutn/exit the scope of the function. Meaning you can not use it like that. Only way to get around that is to make the allocation in the scope where the object is created.
If you do it like you did it might compile and work in some cases. But in reality you are using stack memory that the program sees as free and might be occupied by other stuff. So it's an undefined behavior.
Alloca is awesome, but dangerous if used wrong like that. Should make eha clear.
YESSSSS
suggestion: please keep your video without any background music. NO MUSIC, please
I love your video they are informative and concise.
Suggestion: I know this isn't a data structure, but somewhat related. Could you talk about endianness and how to deal with it? I suppose this is more to do with data punning than anything, but as a firmware engineer working in c, it would be nice to know how one deals with it in c++.
Continue this, Implement other data structures like List Set Map Binary Tree
Does anyone know which theme he uses for Visual Studio?
What if I want put my array in function method? I don't want care about size. I want use Size()! Again, I have to use template?
tamplate
function doSomthing(Array arr){
...
}?
So if i have hundred or thousand of diffrent arrays I have to alwase make copy of function who will do stuf?
Did I miss understand it?
Should I create second function to handle size ? To avoid make copy of huge block of code? Grrr... More I am thinking about it, more it become complicated.
Awesome! Would love to see more data structure videos :)
I dig arrays but it feels like whenever I'm writing a program (mind you I'm not a programmer by education or profession, I just have had some classes in my degree), it's a case where you ask the user the size of the container (or the data set to be more accurate) if you're not reading it from a file. And c++ doesn't let me get that size, then create an array with that size and use it, it demands a const size that apparently needs to be set at compiling.
Although at some point I somehow managed to make it compile with the user input variable size for array size, I have no idea why. It got very upset some days later and redlined it hard. Somehow I had managed to make some sort of loophole around it. Maybe it treated it as heap allocated somehow.
It would be really nice to get those turned into stack allocated arrays though, because every function used all the data in the container.
Maybe if there was a good idea of the limits of the data set, but I find that the programs I've written to help with some stuff should allow quite big sets, even though I might use it for small sets especially in testing.
In general, I find that most if not all of my programs revolve around asking user input and then calculating something. Programming would be so nice if it was done without user inputs. Especially Rust would be nice to use without.
Can't you use const for the size issue ? You said template is the only solution for that issue.
I find it interesting that the debugbreak doesn't work on the const reference of our array.
_malloca should be used, it is a version of alloca with security enhancements.
Hey how do I add external libraries in visual studio please ...
Hey just wondering if I can get your visual studio config in terms of colors? Hope you understand what I mean
We can technically define:
const int size = 7;
And before using it to define an array, we can change its value via a pointer like this:
int c = 5;
const int a(c);
cin >> (*(&c + 1));
int array[a]
//////////
Now I know that array size must be declared at compile time but this just works... I wonder what strange behaviours will be caused by this hmmmmm...
Would you make a video about constexpr and noexcept
Is there a reason the Data() function returns a pointer rather than an address like the operator[] function? I saw your references video and know they are very similar, but not sure if it matters in this case.
Thanks for these awesome videos by the way!
The TAs at my Data Structures class allocate *everything* in the heap, even objects which already allocate to the heap by themselves. And they don't even care about releasing the used memory before ending the program.
The program may compile and run one way or the other, but I think that's a very bad habit (and bad habits die hard). At least they could tell us we shouldn't do that in production environments or something like that.
Those people usually come from Java where you "new" everything and never delete