9) (b) The queue uses FIFO (First-In-First-Out) principle. 8) (b) Queue data structure is used for allocating resources and scheduling. 3) (b) In queue element is inserted at one end called rear and deleted at other end called front. Remove/access elements at the opposite end. 1) (b) In stack, push means inserting an element and pop means deleting an element. Only allows you to add elements at the “front”, while only allowing you to While a stack only allows you to access its elements at one end, a queue Template class stack : private std :: forward_list Queues We usually visualize a stack vertically, with the accessible end on top: That all these operations take constant time). Only use the operations push_front, pop_front, and maybe head (substitutingīack for front would work, too, but working from the head guarantees ![]() E.g., you can think of it as a list where we can On top of lists (they can be built on top of other data types, like vector,Ī stack is a data structure where elements can be added, removed, and possiblyĪccessed only at one end. Today we’re going to look at a number of data structures that can be built ![]() This allows you to start at any node, and Want to walk the entire list, instead of checking for nullptr, have to checkįor the node that they started at. (In a doubly-linkedĬircular list, prev of the head of the list points to the tail.) Loops that ![]() Not to nullptr, but back to the head of the list. If implemented with an array or vector, it would be O(n) because you have to move other elements to create the space for the new element, or fill the space of the deleted element. The insertĪnd remove operations preserve sorted-ness of the list.Ĭircular lists: the tail" element of the list has its next pointer point, For the queue, a linked list would provide faster results when manipulating data in the middle of the queue (add/delete): O(1). Ordered lists: like the ordered array from the first assignment. Inductive lists: write out the inductive definition, write the struct, write “reversing a list” problem, because it leads into stacks. Linked lists: draw some diagrams, go over some operations.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |