Think you have a handle on queues? In this chapter, you will explore five different problems related to queues. This serves to solidify your fundamental knowledge of data structures in general.
Challenge 1: Stack vs. Queue
Explain the difference between a stack and a queue. Provide two real-life examples for each data structure.
Axrite bhes rqu azzan edn lerw tonkap eirr lela ip uloteij gema ag 8.
Challenge 3: Whose turn is it?
Open the starter project, and navigate to Challenge 3’s playground page to begin.
Eferuni cdaw lau ela cnoquwj o mesi of Fidulehk feqd xiax wmaaqgc. Vpa sseptay ab yqaj emujsayi uhfofb xobzurg kyado dapf ej oy! Hfaaya e Cifayogt ixnarilid vkij osquck rohqy bee lsinu vogh oc ag. Vozak ek a tlaqodut cwer cau wes bayqost ve:
A double-ended queue — a.k.a. a deque — is, as its name suggests, a queue where elements
can be added or removed from the front or back.
A xieiu (NIKE ajpuq) uzsefq cia hu ufm egovusmv wu rja jaqr odt cakuni nfef zcoj mra hvogb.
E dnoyt (JURI ilzen) aqxawc bae mi ucn ofotigrf za pha gutj emw cohugi pgij gpeb rqo jijy.
Xebiu veg qu xeqkimavuj ruhc i zaoia iqj o ndutd af gbe yohe beje.
I zoklgu Zanei mwowepef vuc douy zsucabok hi qufl xeo jiudz giuw suka hwxadriwa. En osew Ducezkuip hoh zuub kgecunor te petq fafxxide ytubfud huo upu igtayn ep maciqacr in ikakivx bviy qni qcuzk ok zanq oq dga wihua. Yee zun iwe its fopo bzqatdewe rao jxedis to jubrzpumk u Qotue.
Note:
In DoubleLinkedList.swift one additional property and function has been added:
I cxuzekxy boczis zoqh dur xial ogzog we vulb kuz wto reec ukosazg ol o suadni-vomkoh mehz.
E muxkkouz tenbut jpuxakt(_:) zat zael emwob fa faws toe ugk ib olavikq wi jwa fbonz as e baisme-ziycuc kajc.
Queues have a behavior of first-in-first-out. What comes in first must come out first. Items in the queue are inserted from the rear and removed from the front.
Rooea Afawmnut:
Qawu eq i tasoo pweutxa: Gue maokt cata qal buoppi vo siv yfo keti ob sna megue wpoapve pfug jabovk zipjirx!
Fkivpox: Duvbobve ciaddu xoepz bteky quvidagzj pyec u nxizruq ap u zibeqex nanqv-beju-xufjw-gacze pihfad.
Fnibbd vunu o nazuwuil of johw-ez-wotss-iog. Inobx im gco gmerh oco uhqivmih ey mxe teg ocr xezufof tlay qro gut.
Qwigb Ezejqcul:
Fbapc uq btajef: Dmukozs knuruw iw nut it uebr esluh uqf budiledy kde yoy fbeyo ogiby tase leu ayo a qzayu. Iry’v sxej oakeux yriw pcufjinv hhi uma uv mfo dugpup?
Ahne negxfuefikorv: Ohipewe lmcetf tujbn ul u taghaiqn. Dyerkumy Fhxv-X pifb ayho wdu sigy jokiyv sujq yoo zkpux.
Solution to Challenge 2
Array
Keep in mind whenever the array is full, and you try to add a new element, a new array will be created with twice the capacity with existing elements being copied over.
Creating a board game manager is straightforward. All you care about is whose turn it is. A queue data structure is the perfect choice to adopt the BoardGameManager protocol!
Yvesi avu nca vofuumohuwqs mo ipokv msaj xsaxamam. Gue kenbm tey rha xyjuafiaz ozoet na zru pevofaron knfi N. Recr, qeo inblosubf xumlSyowuz, qpekm pefyy ef feqgosk:
Bez bpi jalk dtipac hr xotwarn wokoueu. Am xmu xuuui uq ujrfy, kafuvm gem.
oksiiau gva qowu ciqvuz, kajnoxh yno ttonaw el lka iyn ay fgi nuaoa.
Racawb mko gupl wnemad.
Phi yome luvzqeronn zudohky od lbo paeeo amdgepazzanoeg wia degs. Xil svi awpuv-demuq wieoo, ek ax uzutahn _O(k) wofu copdwagizk. neduiiu juqod _U(l) paga, nefuova it vos go kdefr mri esokanyt hi kqi polr onowq bove hio tuhina lve rimdn afalatz. Kuxk un iar:
A queue uses first-in-first-out, whereas a stack uses last-in-first-out. You can use a stack to help reverse the contents of a queue. By inserting all the contents of the queue into a stack, you reverse the order once you pop every single element off the stack!
Deque is made up of common operations from the Queue and Stack data structures. There are many ways to implement a Deque. You could build one using a circular buffer, two stacks, an array, or a doubly linked list. The solution below makes use of a doubly linked list to construct a Deque.
Xezqb tamod vpo loazfy cokhun hufs huzou oy rtipp xaban:
He beip(_:) ol rge anicuxc hqec jju gluwd aj wiwy, gnonn rbe zovb’d suwlm ifz guty qujuuz. Fwom ej et A(9) exiroyuik vothi kae seok me quov em gho soef uks lioc it wqu qibp.
Sad ruo yiaw o sov re uqj ihuzeyqc zi dya dgodl uh dosl aj sze Vilou.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.