Let's not look at other tech and we will also get them off it. 2
We would see its usage as boutique Q as well as a stock as the name implies it is an implementation 3
of a direct interface and is resizable. 4
So internally it uses an Id just like an idealist. 5
It was added in July 6 which means that it is a fairly new data structure. 6
And since it is a deck we know that it can it both before and before. 7
And these are the different ways. 8
Creating an idyllic it can be unbonded or you can specify a fixed capacity or you can also construct 9
it with the elements from the specified collection. 10
Not that unlike a linked list which is also a deck other deck prohibits null values. 11
Ok so you cannot add an old values and similarly unlikely English it does not implement the list interface 12
. 13
So it is a pure Q implementation. 14
Novin we need to use a better implementation. 15
It is recommended to use an Arabic rather than a linked list. 16
And here are some reasons for that. 17
One of them is from Java dock itself. 18
It says that it is likely that an array deck is faster than linguist's if the linked list is used as 19
a queue. 20
There is also an article whose link is provided in the resources section and it proves that Arek is 21
at on three times faster than a linked list for large groups. 22
The main reason for that is that link list we have to create an additional node object with every newly 23
added element right. 24
We saw that in the linked list lecture that would take more time and would also mean more memory footprint 25
. 26
Similarly when the element is remote the object needs to be garbage collected. 27
And so if there are a lot of elementary movers then it will load on the DC process. 28
Also if you do a bit of hard thinking you make definitely come across this dot right. 29
Why cant we use an idealist as if fearful we simply need to use the odd method for adding an element 30
of pain and the removal of zero for removing the element from the head. 31
There are few good reasons why you should not use another list on other deck would still be our best 32
bet for you. 33
One reason is performance. 34
We know that in working remote off zero on an oral test which if all the subsequent elements. 35
So it has a linear time complexity and it only gets back with a large number of elements because we 36
how more and more dimensions. 37
In fact according to one benchmark linked list was 20 times faster than our list product foredeck do 38
you like Access 2000 elements who are used so Elliman chefs is definitely a killer. 39
Link to the benchmark is included in the resources section. 40
So you might next ask what about the men chef in an article as it is also at based base just like an 41
idealist. 42
We dont have 11 shifts bit with a deck as its implementation is based on something called its circular 43
area which does not in ball and dimensions. 44
OK. 45
So it has more to do with the algorithm to make logic. 46
So it would be constant time for adding and removing at both ends. 47
Now another reason why idealists should not be used as a cue is your intention from a design perspective 48
. 49
Indention been using a red deck is to use it as a fee for Ardsley for which involves on the head or 50
tail manipulations method names like pop beak and push very clearly reflect that. 51
But with other list we did not constrain ourselves to or meet her dentate right under the complexities 52
of the methods. 53
Most methods run in a monetised Constantine that is then mostly constant time summiteers that deal with 54
the remolding are searching for specific objects one billion years as we know because Can that you not 55
that here we are talking about the remote off object method and not the moment. 56
But empty parenthesis which is constant. 57
Finally keep in mind that there is no way for us to add something in the middle Ah-Q all the internal 58
elements can be deleted using these at the moment it's that busy here. 59
So that's about it. 60
No let's go ahead and Bushrod them off autistic. 61
OK for this demo we're going to add a new class called that's cute. 62
All of it is added to this package. 63
Class collections that you deem a class has a motet deck test which we are going to fill in now. 64
So it does not mean we are going to create an instance of our deck and we will use it as both a queue 65
as well as us duck. 66
OK so let's just go ahead and do that. 67
So the reference type would be deck under deck which stored on these strings. 68
Case select mean book already on deck. 69
Now let's just go ahead and add some elements. 70
So first let's do. 71
Let's use it as a Q. 72
OK which is official. 73
Let's try to have some books here. 74
That's our first book. 75
Wilden a very nice book. 76
A nineteenth century classic and lets out Harry Potter. 77
And finally let's ired head first Java which is a great beginner level book quarte Java and there's 78
also the commander and this course. 79
Now let's put this statement here and let's say branding. 80
Q And let's pretend all that three books. 81
OK so this all goes space nuts. 82
So we need to remove from the head and for that we know we can use the remote method. 83
Right. 84
So that would remove the element on would also get on that end. 85
So let's call this let's do it. 86
The second element also has the third element. 87
Now it can be removed or you can also use it to move fast. 88
Right. 89
Because I've just got a Spawn's to head. 90
So you just go ahead and run this. 91
This method is and will Crome the main method. 92
So it is bending the elements. 93
So the first element that got added was Brandon underspending round and then the second element then 94
the third element. 95
OK so that is powerful. 96
Now let's go ahead and also do the same for a stack. 97
So let's implement as a stack. 98
So at this point the deck is empty because we removed all the elements that what I did. 99
So we can just reuse the same deck. 100
I let's use it as a stack so let's just say stack last and just out. 101
Now let's go ahead and push the same elements. 102
OK. 103
So let's use a push method. 104
Don't push it 105
. 106
OK. 107
So the elements have been pushed now to remove the elements. 108
We can just use the pop method. 109
So let me just copy this. 110
This time it would be stuck. 111
So here we just say pop 112
that Sir sort of says go ahead and run it. 113
Now as you can see the elements are the stack. 114
They're getting pretty good in the reverse order because it doesn't last. 115
And fast. 116
So the last N elementals head first Java and that is garding. 117
Bob don't just. 118
So that's it. 119
So stack is something we have already seen ret in GBM also the IBM also implements its metor in most 120
patients using iStock. 121
OK on is also used in many places. 122
It's also used in a framework called Executive framework which you will see in the collections Shapter 123
which is used to manage the threats threat management third management there the executive framework 124
makes use of a. 125
OK. 126
So you is also used. 127
So that's about it. 128
So these are the things. 129
And we also know that a linked list also implements direct interface. 130
In addition to a list. 131
So if we can import this 132
and see the same output. 133
So long list also can be used. 134
But as we discussed earlier if you want a deck implementation you should go get utterer dick. 135
OK so that's the recommended approach. 136
Is that a commander implementation. 137
So that's about it. 138
Thank you. 139
And you can find this code in the resources section and that's it. 140
I'm happy coding.