Lecture 95: Implement two stacks in an array | N Stack in an Array

preview_player
Показать описание
Stack | 180daysofCode | Solve Many Problem on Stack

00:00 Intro
00:48 Problem 1 - Implement two Stack in an Array(Approach 1)
03:27 Approach 2 - Implement two Stack in an Array
14:22 Code Part - Implement two Stack in an Array
20:11 Problem 2 - N Stack in an Array (Approach 1)
21:46 Approach 2 - N Stack in an Array
22:31 Discussing Main Solution - N Stack in an Array
53:57 Code Part - N Stack in an Array
57:25 Homework

Day 141/180, #180daysofcode #180 hard

We are doing 180 days challenge and going to complete the whole course within the duration with quality content on Youtube. I am on the mission to create a tech revolution in our country and in upcoming future we want to create a tech which will create many jobs in India.

Video will come on Mon-Fri at 6am in the morning

DSA Course for free
C++ Free Course
Rohit Negi DSA Course C++
Coder Army DSA Course c++
Function in C++
Pointers in C++.
Strings
Vector
Introduction to Recursion

Рекомендации по теме
Комментарии
Автор

Guys please like kiya karo .... he is doing this everything for free so in return we all should as a gurudakshina or kuch nhi to like or comment to kar hi sake hena....

Thank You Bhaiya for everything ... ❤

KaranS_uthar
Автор

I watched more than 5 videos and finally found what I Thank you sir ❤

abhishekchaturvedi
Автор

Uses of Stack

1. Browsers remember your history with stacks.

2. Stacks can be used to implement the undo button in text editors.

3. Function calls are handled Stacks.

4. Math expressions evaluation.

5. Stacks track steps in tricky problems, like mazes.

sagestudy
Автор

2 months ago :- what is DSA
Today :- 50% DSA concept covered by coder army ❤

rishabhshenoy
Автор

finally chamak gya bhaiya....
I was stuck in prev lec for 3 days since that hard problem was too complex. And during this time i explore more about subarray form basic to hard level and solve the same given problem with 1 optimize approach which i explored myself. But have used your concept...
Thank you so much bhaiya ....🩷🩷

Bs ab wait hai 16th of sept ka... ab DEV. v start kr denge... and will balance both parallelly.

luvkingprince
Автор

Best lecture... Par ye questions college wali mam ne bhi karwaya tha..❤

Karamjeet_
Автор

i don't know if it's the correct solution or not because we have used linked list too and not just arrays.... but i must say i haven't seen this solution anywhere else and according to me it's the easiest solution for this problem i have seen so far

parthdeshwal
Автор

This is really great stack series.
Thank you bhaiya❤

Gyanendra
Автор

chamak gaya bhaiya ekdum ache se...
bs thoda aur practice aur dry run karunga.... 💓💓

apatiladitya
Автор

i solved first problem using odd and even pointer for two stacks respectively:
class twoStacks {
public:
int *v;
int i, j;
twoStacks(int n=100) {
v=new int[n];
i=0, j=1;
}

// Function to push an integer into the stack1.
void push1(int x) {
// code here
if(i<=99){
v[i]=x;
i+=2;
}
else return;
}

// Function to push an integer into the stack2.
void push2(int x) {
// code here
if(j<=100){
v[j]=x;
j+=2;
}
else return;

}

// Function to remove an element from top of the stack1.
int pop1() {
// code here
i-=2;
if(i>=0){

int pop=v[i];

return pop;
}
else {
i=0;
return -1;

}

}

// Function to remove an element from top of the stack2.
int pop2() {
// code here
j-=2;
if(j>=0){

int pop=v[j];

return pop;
}
else {
j=1;
return -1;

}
}
};

Gyanendra
Автор

Good morning sir, chamak Gaya sir, unique content

SUN_SUN
Автор

Thanks Rohit Bhai for your wonderful explanation ❤

souravsanyal
Автор

6:42 Implement two stacks

class twoStacks
{
public:

int arr[200];
int top1;
int top2;

twoStacks()
{
top1 = -1;
top2 = 200;
}

//Function to push an integer into the stack1.
void push1(int x)
{
top1++;
arr[top1] = x;
}

//Function to push an integer into the stack2.
void push2(int x)
{
top2--;
arr[top2] = x;
}

//Function to remove an element from top of the stack1.
int pop1()
{
if(top1 == -1){
return -1;
}
int num = arr[top1];
top1--;
return num;
}

//Function to remove an element from top of the stack2.
int pop2()
{
if(top2 == 200){
return -1;
}
int num = arr[top2];
top2++;
return num;
}
};

allinonemoviesyt
Автор

2nd day for me: I hope you will notice daily, thanks and much love bro.

suniljadaun
Автор

Bhaiya 2nd wala problem ka solution

Was just

ankushladani
Автор

bhai maza agya n stacks pad gaya better than any other solution

akashsuri
Автор

Implementaion of 2 Stacks in a Single array

public class ImplementTwoStackInAnArray {
public static class Stacks {
static int[] arr = new int[10];
static int n = arr.length;
static int top1 = 0;
static int top2 = n - 1;
}
public static class Stack_1 extends Stacks {
public void push(int val) {
if (top1 >= top2) {
System.out.println("Stack Overflow");
return;
} else
arr[top1++] = val;
}
public int pop() {
if (top1 > 0)
return arr[--top1];
return -1; // if stack 1 is empty
}
public void display() {
for (int i = 0; i < top1; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
}
}

public static class Stack_2 extends Stacks {
public void push(int val) {
if (top2 < top1) {
System.out.println("Stack Overflow");
return;
} else
arr[top2--] = val;
}
public int pop() {
if (top2 < n - 1) {
return arr[++top2];
}
return -1;
}
public void display() {
for (int i = n - 1; i > top2; i--) {
System.out.print(arr[i] + " ");
}
System.out.println();
}
}

public static void main(String[] args) {
Stack_1 st1 = new Stack_1();
st1.push(1);
st1.push(2);
st1.push(3);
st1.push(4);
st1.push(5);
st1.push(6);

st1.display();
System.out.println("Stack 1 poped element = " + st1.pop());
System.out.println("Stack 1 poped element = " + st1.pop());
st1.display();

Stack_2 st2 = new Stack_2();
st2.push(11);
st2.push(12);
st2.push(13);
st2.push(14);

st2.display();

System.out.println("Stack 2 Poped element = " + st2.pop());
st2.push(15);
st2.push(16);
st2.display();

}
}

gangwarsaurabh
Автор

N array stack question ke youtube par bohot video hai but esa solution aur explanation kahi nhi dekha.

demoDevv
Автор

u got new subscriber ....ur junior btw...from IIT not describe in words what level of motivation u are...for of love

chanchalsoni
Автор

maja aa gya..❤️bhaiya pls hashmaps bhi lijiyega...

theskyispink
visit shbcf.ru