Join Raghavendra Dixit for an in-depth discussion in this video Double-ended queues using arrays, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] Now let's see…how we can implement our DE queue using an array.…First we create a new array of int type,…of some size, say eight.…Then we initialize the head and tail…with a value of minus one,…since there are no elements in the array right now.…Now let's say we want to add a new element, seven,…from the right.…As it is the first element, it doesn't really matter.…We do this…by incrementing the value of both head and tail by one,…and updating the data at the zeroth index to seven.…
Now, when we say we want to insert it from the right,…it means that we want to insert it at the tail.…Whenever we want to insert a new element at the tail,…we need to increment the value of tail by one,…and then update the data at that index.…So here, to insert the element 12 at right,…we need to increment the value of tail by one,…and then update the data at the tail index,…which is the first index right now, to 12.…
Now let's say we want to add a new element, 14,…from the left.…When we say left, we really mean at the head,…
Note: This course was created by Packt Publishing. We are pleased to host this training in our library.
- Why study data structures and algorithms?
- How to calculate the time complexity
- Using Big O notation
- Using basic sorting and search algorithms
- Searching elements in unordered arrays and ordered arrays
- Implementing a linked list in Java
- Implementing stacks using arrays
- Queues using arrays
- Binary search trees
- Representing heaps using arrays
Skill Level Intermediate
1. Introduction to Algorithms
2. Analysis of Algorithms
3. Basic Sorting and Search Algorithms
4. Linked Lists
5. Stacks and Queues
7. Binary Search Trees
8. More Sorting Algorithms
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.