Not look at the Q&A phase which is also it Subang to face off collection. 2
Jews are useful then we need to manipulate head and head being the first element whitetail. 3
The last one on the last element is the element which got added most recently so elements that are in 4
detail and also elements are removed or recruit from the head. 5
When we say remote it means the element is actually removed from the queue. 6
But when we say retrieved it means that the element head is simply written but not removed from the 7
queue and we need such Haddonfield manipulations. 8
When we are modelling a fistful of photons far fast and fast out that is the element that gets added 9
fast villi be the element that will be removed fast. 10
So to use more fearful and in real world just like the regular use which we see everywhere. 11
The person who stands first in the queue is the person who is so fast just can contain duplicates. 12
Undergirding knows Huisken hobnails but generally most kewl implementations do not support noce recall 13
that link list which is also a queue allows Null-A use but generally even if notes are allowed you should 14
avoid inserting them unviewable the reason for that and the next slide. 15
Note that unlike list interface queues or any off it some interfaces do not support indexed access to 16
its elements. 17
OK. 18
And generally queues are less frequently used compatriots. 19
It would of course depend on the software that you are developing but generally queues are less frequently 20
used paperless. 21
No limitation to methods that a queue inherits from collection it of is to also add new methods that 22
are specific to head and daily manipulations on these new methods are supported in two forms as indicated 23
by the columns in this table. 24
One of them throws an exception if an operation fails while the other returns a special value which 25
could be either Null are false. 26
So if an operation fails those methods can be done if they're not and are false. 27
So to insert an element into the queue we can use either. 28
I'd offer it then. 29
So both methods are elements to the tail as elements are always added to it. 30
On both methods return a true IF element can be successfully added But if the Q is a capacity to stick 31
that Q Which means that the size is fixed then I'd mattered to an illegal state exception. 32
If the element cannot be added as the queue is full. 33
However if is full the often method which simply add and enforce. 34
So for capacity to stick that gules it is preferred to use the offer a method when compared to the Add 35
method as it does not do an exception Onsen bit it does for us. 36
So you don't need to add runtime exception but can perform some ordinary action. 37
If the matter was mixed both removing pool would be removed had the element of the queue is empty then 38
removed an exception well-poised would return a null value rather than false. 39
OK so just keep that in mind. 40
It would be done in non-value rather than false. 41
Now earlier we said that even if a particular Q implementation accepts a null value we should not insert 42
null on that was that you do. 43
That's like point north Fullerton's or not. 44
It would not be clear whether the head element is not or whether the Q itself is empty. 45
Right on Finally element and Biek are inspection methods. 46
That is to simply written the handling but will not remove it from the queue. 47
Once again if the queue is M-B element method would throw an exception. 48
Well peek would read and not the value. 49
Now let's look at DEC which is a sub interface argue because simply shopfront double and Q Which means 50
that elements can be added and removed at both ends of the queue with you. 51
Elements could be added only at the remoted header as it is a queue. 52
Of course Murdo's fearful but additionally it can also mortal a little bit stands apart. 53
Last In First Out That is the element that got added last would be the element that could be removed 54
first. 55
That is the element that got added most recently is the element that will be removed first. 56
Stocks exhibit default behavior. 57
Recall that GBM uses a stack for keeping clock off method invocations. 58
There is actually a legacy class called stock and if you recall an introductory lesson and this chapter 59
we saved the dollar docs recommend using an array rather than a stack. 60
Ok I stock because legacy or not it will be discussed next on and dumps of DEC implementations. 61
Dick is the most commonly used implementation. 62
Also as we've discussed in the link Lawson a linked list can also act as a deck in addition to being 63
a list and there are also concurrent link back and link blocking deck both of which are related to concurrency 64
So we may look at them later but not for now. 65
Now let's consider this Dec illustration which has had it not since I don't recall operations can be 66
performed on either. 67
And DEC introduces the notion of first and last their first got response with the end of the present 68
head. 69
Why Lascar response to the present state. 70
So the method specific to adding or removing elements to both first and last. 71
Unless you look at them. 72
Let's look at methods that deal with the. 73
And that represents last since Dec extends do you still how I an offer on that it also meant that I 74
had lost an offer last under exactly identical to IDE and offer. 75
Next we have removed last and last with simply remove the last elements. 76
Just note that like in the case of Q Dick also supports the two versions of methods where one Roshan's 77
was an exception but the other returns a special value like false on them. 78
Finally there are also the inspection methods get lost and be classed. 79
So as you can see the methods are meaningfully named because we are dealing with the underlip doesn't 80
last. 81
OK that is there. 82
And here are other methods that deal with the. 83
And that represents just that is had on the first two sets of methods which are emphasized and read 84
other ones which we saw earlier on. 85
Third one is the remote first or point first which are same as remote on. 86
Similarly get first and first or equivalent to element and Biek methods. 87
Finally we all know how I'd first an offer first which allow adding an element at Heda. 88
OK so they are adding an element at the end of that represents head which is fast Nordica also supports 89
some additional methods whose names represent stack operations. 90
So we help push on pop that push is same as at first. 91
Well pop is same as removalist. 92
Not that Pete. 93
There is also a stack operation. 94
So speak applies to both Q As well as stack. 95
So by default for stack push pop on Biek are dealing with the. 96
And that represents Hydra and it is just a job where designers decided to keep it. 97
But you can see that if you want to you can also support stock behavior by using. 98
I remember last and B-class methods which deal with the and that represents data but business just went 99
with the and that represents head on so we also can go with that. 100
So these are the code that's in Dec and we will look at some of them. 101
I did ask them all that we will do in the next lesson. 102
Underestimate that's like a remote first occurrence. 103
Remove last appearance which D'Ken element as input and would remove the first and last occurrences 104
of that element. 105
So if needed. 106
You can also make use of these methods. 107
Kindly note that there are also something called blocking to use their operations going block. 108
Could instance if we want to add an element into the queue and if the queue is full then the operation 109
would wait until some space is available. 110
Similarly every small operation would wait if the queue is empty and it was great until an element gets 111
inserted will look at a blocking implementation in the concurrency chapter as it will be helpful for 112
in direct communication. 113
OK but as you can see there is one interface quite blocking queue which extends the queue interface 114
and there is also blocking back which extends book deck as well as blocking queue. 115
OK so you can look at the naming convention. 116
It does grokking Beck because it extends rocking. 117
You are also a dick so that's up with the Q interface under some interfaces. 118
Next we will look at other Nick. 119
Thank you