Implement Queue Using Array - The Coding Shala
Home >> Data Structures >> Implement Queue Using Array
Other Posts You May Like
In this post, we will learn how to Implement Queue Using Array and will write a Java program for the same.
Implement Queue Using Array
We will write a simple Java Program to implement queue using the array, Only Push and Pop method we will implement here.
Java Program:
class MyQueue { int front, rear; int arr[] = new int[100005]; MyQueue() { front=0; rear=0; } /* The method push to push element into the queue */ void push(int x) { arr[rear] = x; rear++; } /* The method pop which return the element poped out of the queue*/ int pop() { if(front == rear) return -1; int res = arr[front]; front++; return res; } }
- Queue Data Structure
- Circular Queue Data Structure
- Stack Data Structure
- Implement Stack Using Array
- Implement Stack using Linked List
Comments
Post a Comment