Hello, welcome to the 75th tutorial on the c++ programming series. And in this part we'll be looking at lifts. Lists allow data to be stored similar to an array. It is very cheap in terms of computing power to insert and remove data from a list. But one of the main disadvantages over this is that you can't randomly access an element. Basically, you can't say you want to access an element in the fall, for example, that you need to iterate through the entire array or for the entire array up to the point where you've got your data which can be very expensive in terms of computing power, especially when you get like really big arrays and the applications you know Laura with the stuff as well.
This can grow in size on like arrays or arrays, you have to specify the initial size, wherever that is wire a number or wire the amount of value you give it, whereas lists you do not. So let's go ahead and show you how to Implement lift. personally don't really use a list too much we will use array or vector vector we'll be covering in the next part of the series. So what you want to do is do hash include list is a built in low before and get rid of this for a moment. And we're going to create a list is part of the standard namespace so STD colon colon list. And what we do is angle brackets and in here we specify the data type.
So we'll put int, for integer, but name are lists on my list, I want to do is we're going to say by default, their initial, you can initialize a lot so it's an empty list. Or you can also initialize it by saying you want five values or with a default value of 200. Like said you can grow the size Oh, you can make it have seven items or four item, the what number By default it's going to have five in this example and now what we're going to do is just iterate through each element for STD list in Comic Con iterator the iterator and then name it, we're gonna assign the value of my list of became so the start of the list, but semicolon say it wanted isn't equal to my list can you be can you get to the end so, while still within the list or two, semi colon t plus plus ln here with simply that is STD c out as true to STD and y and if we run this with the values to tune to tune the printed out my settings with six times they've been up, and what we're gonna do is actually show you how to add some data to it.
So to do that, you just do my next you push or pop data push, so we're gonna push it to the back. And when the when the song is 47, right, and the left value is printed at 47. But if we change this to push front, the first value is 47, because you're pushing it to the front of the list. You can also mine this dot pop back. So we'll have 47 plus four 200. Or if we change this to push from pop front running, we get five 200 valleys because even though we pushed some day to font being mmediately popped it that's how you move and into data changes.
Back. Name it for this tutorial. In the next tutorial we'll cover vectors which will allow data to be inserted randomly. If you have any questions feel free to message us our support are some systems that correct Okay, the email will be in the description. You can comment on this video or this direct messages via YouTube. All the recordings from the source code will also be in the description.
And as usual, thanks for watching and have a great day.