+
{paragraphs[1]}
@@ -162,6 +225,35 @@ const content = () => {
+
+ {/* Mobile iframe at bottom */}
+
+ {mounted && (
+
+ )}
+
+
);
};
diff --git a/app/visualizer/stack/isempty/page.jsx b/app/visualizer/stack/isempty/page.jsx
index b9df7c0..659816f 100644
--- a/app/visualizer/stack/isempty/page.jsx
+++ b/app/visualizer/stack/isempty/page.jsx
@@ -1,31 +1,119 @@
import Animation from "@/app/visualizer/stack/isempty/animation";
import Navbar from "@/app/components/navbarinner";
+import Breadcrumbs from "@/app/components/ui/Breadcrumbs";
+import ArticleActions from "@/app/components/ui/ArticleActions";
+import Content from "@/app/visualizer/stack/isempty/content";
+import Quiz from "@/app/visualizer/stack/isempty/quiz";
+import Code from "@/app/visualizer/stack/isempty/codeBlock";
+import ModuleCard from "@/app/components/ui/ModuleCard";
+import { MODULE_MAPS } from "@/lib/modulesMap";
+import ExploreOther from "@/app/components/ui/exploreOther";
+import Footer from "@/app/components/footer";
+import BackToTopButton from "@/app/components/ui/backtotop";
export const metadata = {
- title: 'Stack Visualizer | Learn Stack with Animation and IsEmpty Operation in JS, C, Python, Java',
- description: 'Visualize how Stack works in DSA using interactive animations, including the isEmpty operation. Great for beginners and interview prep. Includes code examples in JavaScript, C, Python, and Java.',
+ title:
+ "Stack is empty Visualizer | Learn Stack IsEmpty Operation in JS, C, Python, Java",
+ description:
+ "Visualize how Stack isEmpty operation works in DSA using interactive animations. Great for beginners and interview prep. Includes code examples in JavaScript, C, Python, and Java.",
keywords: [
- 'Stack DSA',
- 'Stack Visualizer',
- 'Learn Stack',
- 'DSA Animation',
- 'Stack isEmpty Operation',
- 'Check if Stack is Empty',
- 'Stack Implementation in JavaScript',
- 'Stack Implementation in C',
- 'Stack in Python',
- 'Stack in Java',
- 'Stack Code Examples',
- 'Interactive Stack Tool',
+ "Stack DSA",
+ "Stack Visualizer",
+ "Learn Stack",
+ "DSA Animation",
+ "Stack isEmpty Operation",
+ "Check if Stack is Empty",
+ "Stack Implementation in JavaScript",
+ "Stack Implementation in C",
+ "Stack in Python",
+ "Stack in Java",
+ "Stack Code Examples",
+ "Interactive Stack Tool",
],
robots: "index, follow",
+ openGraph: {
+ images: [
+ {
+ url: "/og/stack/isEmpty.png",
+ width: 1200,
+ height: 630,
+ alt: "Stack Peek Visualization",
+ },
+ ],
+ },
};
export default function Page() {
- return(
+ const paths = [
+ { name: "Home", href: "/" },
+ { name: "Visualizer", href: "/visualizer" },
+ { name: "Stack : IsEmpty", href: "" },
+ ];
+
+ return (
<>
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+ IsEmpty Operation
+
+
+
+
+
+
+
+
+
+
+
+ Test Your Knowledge before moving forward!
+
+
+
+
+
+
+
+
+
+
+
+
+
>
);
-};
\ No newline at end of file
+}
diff --git a/app/visualizer/stack/isempty/quiz.jsx b/app/visualizer/stack/isempty/quiz.jsx
index 2266c4d..5cde2bf 100644
--- a/app/visualizer/stack/isempty/quiz.jsx
+++ b/app/visualizer/stack/isempty/quiz.jsx
@@ -1,3 +1,4 @@
+"use client";
import React, { useState } from 'react';
import { FaCheck, FaTimes, FaArrowRight, FaArrowLeft, FaInfoCircle, FaRedo, FaTrophy, FaStar, FaAward } from 'react-icons/fa';
import { motion, AnimatePresence } from 'framer-motion';
@@ -62,37 +63,28 @@ const StackQuiz = () => {
const [showResult, setShowResult] = useState(false);
const [quizCompleted, setQuizCompleted] = useState(false);
const [answers, setAnswers] = useState(Array(questions.length).fill(null));
- const [showExplanation, setShowExplanation] = useState(false);
const [showIntro, setShowIntro] = useState(true);
const [showSuccessAnimation, setShowSuccessAnimation] = useState(false);
- const [penaltyApplied, setPenaltyApplied] = useState(false);
const handleAnswerSelect = (optionIndex) => {
- if (selectedAnswer !== null) return;
setSelectedAnswer(optionIndex);
- const newAnswers = [...answers];
- newAnswers[currentQuestion] = optionIndex;
- setAnswers(newAnswers);
};
const handleNextQuestion = () => {
if (selectedAnswer === null) return;
-
- if (showExplanation && !penaltyApplied) {
- setScore(prevScore => Math.max(0, prevScore - 0.5));
- setPenaltyApplied(true);
- }
- if (selectedAnswer === questions[currentQuestion].correctAnswer) {
- setScore(score + 1);
- }
-
- setShowExplanation(false);
- setPenaltyApplied(false);
-
+ const newAnswers = [...answers];
+ newAnswers[currentQuestion] = selectedAnswer;
+ setAnswers(newAnswers);
+
+ const newScore = newAnswers.reduce((acc, ans, idx) => {
+ return ans === questions[idx].correctAnswer ? acc + 1 : acc;
+ }, 0);
+ setScore(newScore);
+
if (currentQuestion < questions.length - 1) {
setCurrentQuestion(currentQuestion + 1);
- setSelectedAnswer(null);
+ setSelectedAnswer(newAnswers[currentQuestion + 1]);
} else {
setShowSuccessAnimation(true);
setTimeout(() => {
@@ -104,7 +96,6 @@ const StackQuiz = () => {
};
const handlePreviousQuestion = () => {
- setShowExplanation(false);
setCurrentQuestion(currentQuestion - 1);
setSelectedAnswer(answers[currentQuestion - 1]);
};
@@ -116,9 +107,7 @@ const StackQuiz = () => {
setShowResult(false);
setQuizCompleted(false);
setAnswers(Array(questions.length).fill(null));
- setShowExplanation(false);
setShowIntro(true);
- setPenaltyApplied(false);
};
const calculateWeakAreas = () => {
@@ -164,7 +153,7 @@ const StackQuiz = () => {
};
return (
-
+
{showIntro ? (
{
className="text-center"
>
-
Stack Quiz Challenge
-
+
How it works:
@@ -192,10 +181,6 @@ const StackQuiz = () => {
0 points for wrong answers
-
-
- -0.5 point penalty for viewing explanations
-
Earn stars based on your final score (max 5 stars)
@@ -297,29 +282,6 @@ const StackQuiz = () => {
))}
- {selectedAnswer !== null && (
-
-
-
- {showExplanation && (
-
- {questions[currentQuestion].explanation}
-
- )}
-
-
- )}
diff --git a/app/visualizer/stack/peek/animation.jsx b/app/visualizer/stack/peek/animation.jsx
index 998851a..1a399e4 100644
--- a/app/visualizer/stack/peek/animation.jsx
+++ b/app/visualizer/stack/peek/animation.jsx
@@ -1,185 +1,149 @@
-'use client';
-import React, { useState } from 'react';
-import Footer from '@/app/components/footer';
-import PushPop from '@/app/components/ui/PushPop';
-import Content from '@/app/visualizer/stack/peek/content';
-import ExploreOther from '@/app/components/ui/exploreOther';
-import CodeBlock from '@/app/visualizer/stack/peek/codeBlock';
-import GoBackButton from "@/app/components/ui/goback";
-import Quiz from '@/app/visualizer/stack/peek/quiz';
-import BackToTop from '@/app/components/ui/backtotop';
+"use client";
+import React, { useState, useEffect, useRef } from "react";
+import { gsap } from "gsap";
+import PushPop from "@/app/components/ui/PushPop";
const StackVisualizer = () => {
- const [stack, setStack] = useState([]); // Start with empty stack
+ const [stack, setStack] = useState([]);
const [operation, setOperation] = useState(null);
- const [message, setMessage] = useState('Stack is empty');
+ const [message, setMessage] = useState("");
const [isAnimating, setIsAnimating] = useState(false);
- // Add random stack
- const addRandomStack = () => {
- if (stack.length > 0) {
- setMessage('Clear stack first to add new random stack');
- return;
- }
+ const stackRef = useRef(null);
+ const itemRefs = useRef([]);
+ const peekRef = useRef(null);
+ /* ---------- random numbers ---------- */
+ const addRandomStack = () => {
+ if (stack.length > 0) return;
setIsAnimating(true);
- setOperation('Creating random stack...');
-
- const randomItems = ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry']
- .sort(() => Math.random() - 0.5)
- .slice(0, 3 + Math.floor(Math.random() * 3)); // 3-5 random items
-
+ setOperation("create");
+ const nums = Array.from(
+ { length: 3 + Math.floor(Math.random() * 3) },
+ () => Math.floor(Math.random() * 999) + 1
+ );
setTimeout(() => {
- setStack(randomItems);
+ setStack(nums);
setOperation(null);
- setMessage(`Random stack with ${randomItems.length} items created`);
setIsAnimating(false);
- }, 1000);
+ }, 600);
};
- return (
-
-
+ /* ---------- gsap animations (safe) ---------- */
+ useEffect(() => {
+ itemRefs.current.length = 0;
+ if (!stackRef.current) return;
+
+ /* push */
+ if (operation?.includes("push") && itemRefs.current[0]) {
+ setIsAnimating(true);
+ const el = itemRefs.current[0];
+ gsap.set(el, { scale: 0, y: -60, opacity: 0 });
+ gsap
+ .timeline({ onComplete: () => setIsAnimating(false) })
+ .to(el, { scale: 1, y: 0, opacity: 1, duration: 0.4, ease: "back.out(1.2)" });
+ }
- { /* go back block here */}
-
-
-
+ /* pop */
+ if (operation?.includes("pop") && itemRefs.current[0]) {
+ setIsAnimating(true);
+ const el = itemRefs.current[0];
+ gsap.to(el, {
+ scale: 0,
+ y: -60,
+ opacity: 0,
+ duration: 0.35,
+ ease: "power2.in",
+ onComplete: () => setIsAnimating(false),
+ });
+ }
- { /* main logic here */}
-
- Stack Peek
-
-
-
-
- Visualize Push, Pop, and Peek operations
-
+ /* peek */
+ if (operation?.includes("Peek") && itemRefs.current[0]) {
+ setMessage(`Top value is ${stack[0]}`); // ONLY message shown
+ setIsAnimating(true);
+ const el = itemRefs.current[0];
+ peekRef.current = el;
+ gsap.to(el, {
+ scale: 1.15,
+ boxShadow: "0 0 20px #a855f7",
+ duration: 0.3,
+ yoyo: true,
+ repeat: 3,
+ ease: "power1.inOut",
+ onComplete: () => setIsAnimating(false),
+ });
+ }
-
- {/* Controls */}
-
+ /* reorder */
+ gsap.fromTo(
+ itemRefs.current.filter(Boolean),
+ { y: 20, opacity: 0 },
+ { y: 0, opacity: 1, stagger: 0.06, duration: 0.25, ease: "power2.out" }
+ );
- {/* Add Random Stack Button */}
-
+ return () => { peekRef.current = null; };
+ }, [stack, operation]);
- {/* Stack Visualization */}
-
-
Stack Visualization
-
- {/* Operation Status */}
- {operation && (
-
- {operation}
-
- )}
+ return (
+
+
+ Visualize Push, Pop, and Peek operations
+
+
+
+
- {/* Message Display */}
-
+
+
+
+ {/* peek-only message */}
+ {message && (
+
{message}
-
- {/* Vertical Stack */}
-
- {/* Top indicator */}
-
- {stack.length > 0 ? '↑ Top' : ''}
-
-
- {/* Stack elements */}
-
- {stack.length === 0 ? (
-
- Stack is empty
-
- ) : (
-
- {stack.map((item, index) => (
-
- {item}
- {index === 0 && (
-
- (Top)
-
- )}
-
- ))}
-
- )}
-
-
- {/* Bottom indicator */}
-
- {stack.length > 0 ? '↓ Bottom' : ''}
-
-
-
- {/* Stack Legend */}
-
-
-
-
-
Elements
-
Stack items
-
+ )}
+
+ {/* vertical stack */}
+
+
+ {stack.length === 0 ? (
+
+ Stack is empty
+
+ ) : (
+
+ {stack.map((num, idx) => (
+
(itemRefs.current[idx] = el)}
+ className={`p-4 rounded-lg border-2 text-center font-medium transition-all ${
+ idx === 0 ? "bg-blue-100 dark:bg-blue-900 border-blue-300 dark:border-blue-700" : "bg-white dark:bg-gray-700 border-gray-200 dark:border-gray-600"
+ }`}
+ >
+ {num}
+
+ ))}
+
+ )}
-
- { /* quiz block here */}
-
- Test Your Knowledge before moving forward!
-
-
-
-
-
-
-
-
-
-
+
+
);
};
diff --git a/app/visualizer/stack/peek/codeBlock.jsx b/app/visualizer/stack/peek/codeBlock.jsx
index 21e7b91..34b9b13 100644
--- a/app/visualizer/stack/peek/codeBlock.jsx
+++ b/app/visualizer/stack/peek/codeBlock.jsx
@@ -358,10 +358,10 @@ int main() {
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.3 }}
- className="bg-white dark:bg-gray-800 rounded-xl shadow-lg overflow-hidden border border-gray-200 dark:border-gray-700 transition-colors duration-300"
+ className="bg-white dark:bg-neutral-950 rounded-xl shadow-lg overflow-hidden border border-gray-200 dark:border-gray-700 transition-colors duration-300"
>
{/* Header */}
-
+
diff --git a/app/visualizer/stack/peek/content.jsx b/app/visualizer/stack/peek/content.jsx
index 041dad9..09c44ee 100644
--- a/app/visualizer/stack/peek/content.jsx
+++ b/app/visualizer/stack/peek/content.jsx
@@ -1,4 +1,29 @@
+"use client";
+import ComplexityGraph from "@/app/components/ui/graph";
+import { useEffect, useState } from "react";
+
const content = () => {
+ const [theme, setTheme] = useState("light");
+ const [mounted, setMounted] = useState(false);
+
+ useEffect(() => {
+ const updateTheme = () => {
+ const savedTheme = localStorage.getItem("theme") || "light";
+ setTheme(savedTheme);
+ };
+
+ updateTheme();
+ setMounted(true);
+
+ window.addEventListener("storage", updateTheme);
+ window.addEventListener("themeChange", updateTheme);
+
+ return () => {
+ window.removeEventListener("storage", updateTheme);
+ window.removeEventListener("themeChange", updateTheme);
+ };
+ }, []);
+
const paragraphs = [
`Returns the topmost element from the stack without removing it.`,
`The peek operation is useful when you need to inspect the top element before deciding whether to pop it or push another element onto the stack.`,
@@ -17,8 +42,37 @@ const content = () => {
];
return (
-
-
+
+
+
+ {mounted && (
+
+ )}
+
+
+
+
{/* Peek Operation */}
@@ -59,12 +113,50 @@ const content = () => {
))}
+
+ 1}
+ averageCase={(n) => 1}
+ worstCase={(n) => 1}
+ maxN={25}
+ />
+
+
{paragraphs[1]}
+
+ {/* Mobile iframe at bottom */}
+
+ {mounted && (
+
+ )}
+
+
);
};
diff --git a/app/visualizer/stack/peek/page.jsx b/app/visualizer/stack/peek/page.jsx
index 7b3707a..33bb26c 100644
--- a/app/visualizer/stack/peek/page.jsx
+++ b/app/visualizer/stack/peek/page.jsx
@@ -1,32 +1,120 @@
-import Animation from "@/app/visualizer/stack/peek/animation";
+import Animation from "@/app/visualizer/stack/peek/animation";
import Navbar from "@/app/components/navbarinner";
+import Breadcrumbs from "@/app/components/ui/Breadcrumbs";
+import ArticleActions from "@/app/components/ui/ArticleActions";
+import Content from "@/app/visualizer/stack/peek/content";
+import Quiz from "@/app/visualizer/stack/peek/quiz";
+import Code from "@/app/visualizer/stack/peek/codeBlock";
+import ModuleCard from "@/app/components/ui/ModuleCard";
+import { MODULE_MAPS } from "@/lib/modulesMap";
+import ExploreOther from '@/app/components/ui/exploreOther';
+import Footer from '@/app/components/footer';
+import BackToTopButton from '@/app/components/ui/backtotop';
export const metadata = {
- title: 'Stack Peek Visualizer | Understand Peek Operation in Stack with Code in JS, C, Python, Java',
- description: 'Learn how the Peek operation works in a Stack using interactive animations and code examples in JavaScript, C, Python, and Java. Perfect for beginners and DSA interview preparation.',
+ title:
+ "Stack Peek Visualizer | Understand Peek Operation in Stack with Code in JS, C, Python, Java",
+ description:
+ "Learn how the Peek operation works in a Stack using interactive animations and code examples in JavaScript, C, Python, and Java. Perfect for beginners and DSA interview preparation.",
keywords: [
- 'Stack Peek',
- 'Peek Operation Stack',
- 'Stack Top Element',
- 'Peek in DSA',
- 'DSA Stack Animation',
- 'Learn Stack Operations',
- 'Stack in JavaScript',
- 'Stack in C',
- 'Stack in Python',
- 'Stack in Java',
- 'Peek Operation Example',
- 'Stack Code Examples',
- 'Top of Stack',
+ "Stack Peek",
+ "Peek Operation Stack",
+ "Stack Top Element",
+ "Peek in DSA",
+ "DSA Stack Animation",
+ "Learn Stack Operations",
+ "Stack in JavaScript",
+ "Stack in C",
+ "Stack in Python",
+ "Stack in Java",
+ "Peek Operation Example",
+ "Stack Code Examples",
+ "Top of Stack",
],
robots: "index, follow",
+ openGraph: {
+ images: [
+ {
+ url: "/og/stack/peek.png",
+ width: 1200,
+ height: 630,
+ alt: "Stack Peek Visualization",
+ },
+ ],
+ },
};
export default function Page() {
- return(
+ const paths = [
+ { name: "Home", href: "/" },
+ { name: "Visualizer", href: "/visualizer" },
+ { name: "Stack : Peek", href: "" },
+ ];
+
+ return (
<>
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+ Peek Operation
+
+
+
+
+
+
+
+
+
+
+
+ Test Your Knowledge before moving forward!
+
+
+
+
+
+
+
+
+
+
+
+
+
>
);
-};
\ No newline at end of file
+}
diff --git a/app/visualizer/stack/peek/quiz.jsx b/app/visualizer/stack/peek/quiz.jsx
index 31d9905..7a00f63 100644
--- a/app/visualizer/stack/peek/quiz.jsx
+++ b/app/visualizer/stack/peek/quiz.jsx
@@ -1,3 +1,4 @@
+"use client";
import React, { useState } from 'react';
import { FaCheck, FaTimes, FaArrowRight, FaArrowLeft, FaInfoCircle, FaRedo, FaTrophy, FaStar, FaAward } from 'react-icons/fa';
import { motion, AnimatePresence } from 'framer-motion';
@@ -117,37 +118,28 @@ const StackQuiz = () => {
const [showResult, setShowResult] = useState(false);
const [quizCompleted, setQuizCompleted] = useState(false);
const [answers, setAnswers] = useState(Array(questions.length).fill(null));
- const [showExplanation, setShowExplanation] = useState(false);
const [showIntro, setShowIntro] = useState(true);
const [showSuccessAnimation, setShowSuccessAnimation] = useState(false);
- const [penaltyApplied, setPenaltyApplied] = useState(false);
const handleAnswerSelect = (optionIndex) => {
- if (selectedAnswer !== null) return;
setSelectedAnswer(optionIndex);
- const newAnswers = [...answers];
- newAnswers[currentQuestion] = optionIndex;
- setAnswers(newAnswers);
};
const handleNextQuestion = () => {
if (selectedAnswer === null) return;
-
- if (showExplanation && !penaltyApplied) {
- setScore(prevScore => Math.max(0, prevScore - 0.5));
- setPenaltyApplied(true);
- }
- if (selectedAnswer === questions[currentQuestion].correctAnswer) {
- setScore(score + 1);
- }
-
- setShowExplanation(false);
- setPenaltyApplied(false);
-
+ const newAnswers = [...answers];
+ newAnswers[currentQuestion] = selectedAnswer;
+ setAnswers(newAnswers);
+
+ const newScore = newAnswers.reduce((acc, ans, idx) => {
+ return ans === questions[idx].correctAnswer ? acc + 1 : acc;
+ }, 0);
+ setScore(newScore);
+
if (currentQuestion < questions.length - 1) {
setCurrentQuestion(currentQuestion + 1);
- setSelectedAnswer(null);
+ setSelectedAnswer(newAnswers[currentQuestion + 1]);
} else {
setShowSuccessAnimation(true);
setTimeout(() => {
@@ -159,7 +151,6 @@ const StackQuiz = () => {
};
const handlePreviousQuestion = () => {
- setShowExplanation(false);
setCurrentQuestion(currentQuestion - 1);
setSelectedAnswer(answers[currentQuestion - 1]);
};
@@ -171,9 +162,7 @@ const StackQuiz = () => {
setShowResult(false);
setQuizCompleted(false);
setAnswers(Array(questions.length).fill(null));
- setShowExplanation(false);
setShowIntro(true);
- setPenaltyApplied(false);
};
const calculateWeakAreas = () => {
@@ -219,7 +208,7 @@ const StackQuiz = () => {
};
return (
-
+
{showIntro ? (
{
className="text-center"
>
-
Stack Quiz Challenge
-
+
How it works:
@@ -247,10 +236,6 @@ const StackQuiz = () => {
0 points for wrong answers
-
-
- -0.5 point penalty for viewing explanations
-
Earn stars based on your final score (max 5 stars)
@@ -352,29 +337,6 @@ const StackQuiz = () => {
))}
- {selectedAnswer !== null && (
-
-
-
- {showExplanation && (
-
- {questions[currentQuestion].explanation}
-
- )}
-
-
- )}
diff --git a/app/visualizer/stack/push-pop/content.jsx b/app/visualizer/stack/push-pop/content.jsx
index a06878e..bb2e914 100644
--- a/app/visualizer/stack/push-pop/content.jsx
+++ b/app/visualizer/stack/push-pop/content.jsx
@@ -103,7 +103,7 @@ const content = () => {