Stack using Deque in Java | Smart DSA Concepts Explained | StackDeque Class 💡🎓
Автор: S.L.ACADEMY
Загружено: 2025-11-08
Просмотров: 47
Welcome back to the SL Academy DSA Series! 🎓
In this video, we explore how to implement a Stack using Deque in Java — a modern and efficient approach to stack operations.
You’ll learn:
📍 What is a StackDeque
⚙️ How to push, pop, and peek elements
🧠 Why Deque is better than the old Stack class in Java
💻 Step-by-step code explanation (Code below 👇)
class StackDeque_T_ {
private final Deque_T_ dq = new ArrayDeque_T_();
public void push(T x) {
if (x == null) throw new IllegalArgumentException("Null not allowed");
dq.addLast(x);
}
public T pop() {
T val = dq.pollLast();
if (val == null) throw new NoSuchElementException("Empty stack");
return val;
}
public T peek() { return dq.peekLast(); }
public int size() { return dq.size(); }
public boolean isEmpty() { return dq.isEmpty(); }
public void clear() { dq.clear(); }
}
// Example usage
StackDeque_Integer_ s = new StackDeque_Integer_();
s.push(9);
s.push(7);
s.push(11);
System.out.println(s.pop()); // 11
System.out.println(s.peek()); // 7
System.out.println(s.size()); // 2
💙 Follow for more CS & Tech content!
📍 SL Academy (Educational Page)
Instagram: @SL_ACADEMY
TikTok: @SL_ACADEMY
🧑💻 Personal Accounts (Creator)
Instagram: @Sav_nimhari
TikTok: @Sav_nimhari
👍 Don’t forget to Like, Share & Subscribe for the next DSA concept — Queue using Deque coming soon!
🔥 Hashtags (same as first + new ones):
#DSA #DataStructures #Algorithms #StackDeque #JavaProgramming #SLAcademy #SavNimhari #LearnCoding #ProgrammingForBeginners #ComputerScience #SoftwareEngineering #CodingCommunity #StudyWithMe #TechEducation #SriLankaStudents #codingjourney
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: