@@ -89,7 +148,10 @@ const content = () => {
{implementationSteps.map((item, index) => (
- -
+
-
{item.points}
))}
@@ -97,23 +159,6 @@ const content = () => {
-
{implementationSteps.map((item, index) => (
-
- +
- {item.points} ))} @@ -97,23 +159,6 @@ const content = () => {
- - Basic Class Structure -
-
-
- {arrayImplementationCode.map((item, index) => (
- {item.code}
- ))}
-
-
-
@@ -123,16 +168,14 @@ const content = () => {
{enqueueAlgorithm.map((item, index) => (
- -
+
-
{item.points}
))}
-
-
- Circular Array Note: The modulo operation (% capacity) enables the circular behavior by wrapping the pointer to the start when it reaches the end.
-
-
-
{enqueueAlgorithm.map((item, index) => (
-
- +
- {item.points} ))}
- Circular Array Note: The modulo operation (% capacity) enables the circular behavior by wrapping the pointer to the start when it reaches the end.
-
-
{dequeueAlgorithm.map((item, index) => (
-
- +
- {item.points} ))} @@ -162,11 +208,14 @@ const content = () => {
- +
- - {item.points.split(':')[0]}: + {item.points.split(":")[0]}: - {item.points.split(':')[1]} + {item.points.split(":")[1]} ))}
- +
- {item.points} ))} @@ -193,8 +245,10 @@ const content = () => { {/* Additional Info */}
- - {item.points} - - ))} -
-
{complexity.map((item, index) => (
-
-
{prosCons.map((item, index) => (
-
Practical Considerations
++ Practical Considerations +
{paragraph[1]}
@@ -205,8 +259,37 @@ const content = () => {+ Queue +
++ Using Array +
+
+ - Queue Implementation Using Linked List -
- -- Queue Implementation (Enqueue & Dequeue) + Implementation Enqueue & Dequeue
@@ -105,28 +130,6 @@ const content = () => {
- - Basic Class Structure -
-
-
- {llImplementationCode.map((item, index) => (
- {item.code}
- ))}
-
-
- - Note: Each node contains the data and a reference to the next node. The queue maintains references to both ends (front and rear) for efficient operations. -
-
@@ -141,23 +144,6 @@ const content = () => {
))}
-
-
-
- Before Enqueue:
-
- front → [A|•] → [B|•] → null
-
-
-
- After Enqueue(C):
-
- front → [A|•] → [B|•] → [C|•] → null
- (rear updated)
-
-
-
-
- - Operation Visualization -
-| Step | -Queue State | -
|---|---|
| {item.step} | -{item.state} | -
When to Use Linked List Queue
{paragraph[2]} @@ -275,6 +218,35 @@ const content = () => {
+ Queue +
++ Using Linked List +
+
+ + Circular Queue Visualiser (Fixed Capacity) +
- {/* main logic here */} -- Circular Queue -
- -- Visualize Circular Queue Operations -
-- Test Your Knowledge before moving forward! -
-
diff --git a/app/visualizer/queue/types/circular/content.jsx b/app/visualizer/queue/types/circular/content.jsx
index d7f4e0e..fc66a9f 100755
--- a/app/visualizer/queue/types/circular/content.jsx
+++ b/app/visualizer/queue/types/circular/content.jsx
@@ -1,4 +1,28 @@
+"use client";
+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 paragraph = [
`A Circular Queue is an advanced version of a linear queue that connects the end of the queue back to the front, forming a circle. This efficient structure prevents memory wastage and allows better utilization of fixed-size buffers.`,
`The circular queue is an essential data structure for systems requiring efficient, fixed-size buffers with constant-time operations. Its circular nature solves the memory wastage problem of linear queues while maintaining simple and predictable performance characteristics, making it ideal for low-level system programming and real-time applications.`,
@@ -16,16 +40,6 @@ const content = () => {
{ points : "Efficient space utilization: Reuses empty spaces created after dequeues" },
];
- const example = [
- { points : "enqueue(10): [10, _, _, _, _] (F=0, R=0)" },
- { points : "enqueue(20): [10, 20, _, _, _] (F=0, R=1)" },
- { points : "enqueue(30): [10, 20, 30, _, _] (F=0, R=2)" },
- { points : "dequeue(): Returns 10 → [_, 20, 30, _, _] (F=1, R=2)" },
- { points : "enqueue(40): [_, 20, 30, 40, _] (F=1, R=3)" },
- { points : "enqueue(50): [_, 20, 30, 40, 50] (F=1, R=4)" },
- { points : "enqueue(60): [60, 20, 30, 40, 50] (F=1, R=0) ← Wraps around!" },
- ];
-
const implementation = [
{ points : "Pointer Movement:",
subpoints : [
@@ -71,8 +85,37 @@ const content = () => {
];
return (
-
-
+
+
+
+ {mounted && (
+
+ )}
+
+
+
+ Daily DSA Challenge by{" "}
+
+ Hello World
+
+
+
+
+
{/* What is a Circular Queue? */}
@@ -115,26 +158,6 @@ const content = () => {
@@ -115,26 +158,6 @@ const content = () => {
- - Visual Example (Size=5) -
-- Operation sequence on an empty circular queue: -
--
- {example.map((item, index) => (
-
@@ -224,7 +247,7 @@ const content = () => {
{/* Additional Info */}
-
+
{paragraph[1]}
@@ -232,6 +255,35 @@ const content = () => {
+
+ {/* Mobile iframe at bottom */}
+
+ {mounted && (
+
+ )}
+
+
+ Daily DSA Challenge by{" "}
+
+ Hello World
+
+
+
+
);
};
diff --git a/app/visualizer/queue/types/circular/page.jsx b/app/visualizer/queue/types/circular/page.jsx
index 4818bdd..981aa4e 100755
--- a/app/visualizer/queue/types/circular/page.jsx
+++ b/app/visualizer/queue/types/circular/page.jsx
@@ -1,31 +1,119 @@
import Animation from "@/app/visualizer/queue/types/circular/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/queue/types/circular/content";
+import Quiz from "@/app/visualizer/queue/types/circular/quiz";
+import Code from "@/app/visualizer/queue/types/circular/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 BackToTop from "@/app/components/ui/backtotop";
export const metadata = {
- title: 'Circular Queue | Learn with JS, C, Python, Java Code',
- description: 'Understand how Circular Queue works in Data Structures using animations and complete code examples in JavaScript, C, Python, and Java. Ideal for DSA beginners and interview preparation.',
- keywords: [
- 'Circular Queue',
- 'Circular Queue Visualizer',
- 'Circular Queue DSA',
- 'Circular Queue in JavaScript',
- 'Circular Queue in C',
- 'Circular Queue in Python',
- 'Circular Queue in Java',
- 'Queue Data Structure',
- 'DSA Queue Operations',
- 'Learn Circular Queue',
- 'Circular Queue Code Examples',
- 'DSA Visualizer'
+ title: "Circular Queue | Learn with JS, C, Python, Java Code",
+ description:
+ "Understand how Circular Queue works in Data Structures using animations and complete code examples in JavaScript, C, Python, and Java. Ideal for DSA beginners and interview preparation.",
+ keywords: [
+ "Circular Queue",
+ "Circular Queue Visualizer",
+ "Circular Queue DSA",
+ "Circular Queue in JavaScript",
+ "Circular Queue in C",
+ "Circular Queue in Python",
+ "Circular Queue in Java",
+ "Queue Data Structure",
+ "DSA Queue Operations",
+ "Learn Circular Queue",
+ "Circular Queue Code Examples",
+ "DSA Visualizer",
+ ],
+ robots: "index, follow",
+ openGraph: {
+ images: [
+ {
+ url: "/og/queue/circularQueue.png",
+ width: 1200,
+ height: 630,
+ alt: "Circular Queue Algorithm Visualization",
+ },
],
- robots: 'index, follow',
- };
-
-export default function Page(){
- return(
- <>
-
-
- >
- );
-};
\ No newline at end of file
+ },
+};
+
+export default function Page() {
+ const paths = [
+ { name: "Home", href: "/" },
+ { name: "Visualizer", href: "/visualizer" },
+ { name: "Circular Queue", href: "" },
+ ];
+
+ return (
+ <>
+
+
+
+
+
+
+
+
+
+
+
+
+ Queue
+
+
+
+ Circular Queue
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Test Your Knowledge before moving forward!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ >
+ );
+}
diff --git a/app/visualizer/queue/types/circular/quiz.jsx b/app/visualizer/queue/types/circular/quiz.jsx
index cb50411..9b88db9 100755
--- a/app/visualizer/queue/types/circular/quiz.jsx
+++ b/app/visualizer/queue/types/circular/quiz.jsx
@@ -1,142 +1,66 @@
+"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';
const QueueQuiz = () => {
-const questions = [
+ const questions = [
{
- question: "What is the primary advantage of a circular queue over a linear queue?",
- options: [
- "Unlimited capacity",
- "Better memory utilization by reusing empty spaces",
- "Faster sorting capability",
- "Built-in search functionality"
- ],
- correctAnswer: 1,
- explanation: "Circular queues efficiently reuse empty spaces created by dequeue operations, preventing memory wastage."
+ question: "What is the primary advantage of a circular queue over a linear queue?",
+ options: [
+ "Unlimited capacity",
+ "Better memory utilization by reusing empty spaces",
+ "Faster sorting capability",
+ "Built-in search functionality"
+ ],
+ correctAnswer: 1,
+ explanation: "Circular queues efficiently reuse empty spaces created by dequeue operations, preventing memory wastage."
},
{
- question: "How is the rear pointer calculated after an enqueue operation in a circular queue?",
- options: [
- "rear = rear + 1",
- "rear = (rear + 1) % capacity",
- "rear = front + 1",
- "rear = capacity - 1"
- ],
- correctAnswer: 1,
- explanation: "The rear pointer wraps around using modulo arithmetic: rear = (rear + 1) % capacity."
+ question: "How is the rear pointer calculated after an enqueue operation in a circular queue?",
+ options: [
+ "rear = rear + 1",
+ "rear = (rear + 1) % capacity",
+ "rear = front + 1",
+ "rear = capacity - 1"
+ ],
+ correctAnswer: 1,
+ explanation: "The rear pointer wraps around using modulo arithmetic: rear = (rear + 1) % capacity."
},
{
- question: "What condition indicates that a circular queue is full?",
- options: [
- "front == rear",
- "(rear + 1) % capacity == front",
- "front == 0 && rear == capacity - 1",
- "rear == capacity - 1"
- ],
- correctAnswer: 1,
- explanation: "The queue is full when the next position after rear (wrapped around) equals front."
+ question: "What condition indicates that a circular queue is full?",
+ options: [
+ "front == rear",
+ "(rear + 1) % capacity == front",
+ "front == 0 && rear == capacity - 1",
+ "rear == capacity - 1"
+ ],
+ correctAnswer: 1,
+ explanation: "The queue is full when the next position after rear (wrapped around) equals front."
},
{
- question: "Why do circular queues typically maintain one empty slot?",
- options: [
- "To reduce memory usage",
- "To distinguish between full and empty states",
- "For temporary storage during operations",
- "It's required by the implementation language"
- ],
- correctAnswer: 1,
- explanation: "Without one empty slot, the conditions for full and empty states would be identical (front == rear)."
+ question: "Why do circular queues typically maintain one empty slot?",
+ options: [
+ "To reduce memory usage",
+ "To distinguish between full and empty states",
+ "For temporary storage during operations",
+ "It's required by the implementation language"
+ ],
+ correctAnswer: 1,
+ explanation: "Without one empty slot, the conditions for full and empty states would be identical (front == rear)."
},
{
- question: "What would be the state of a circular queue (size=5) after these operations: enqueue(10), enqueue(20), dequeue(), enqueue(30), enqueue(40), enqueue(50)?",
- options: [
- "[10, 20, 30, 40, 50]",
- "[_, 20, 30, 40, 50]",
- "[50, _, 20, 30, 40]",
- "[_, 20, 30, 40, _]"
- ],
- correctAnswer: 1,
- explanation: "Operations: enq(10), enq(20), deq() removes 10, then enq(30), enq(40), enq(50) → [_, 20, 30, 40, 50]"
- },
- {
- question: "Which of these applications would LEAST likely use a circular queue?",
- options: [
- "Round-robin CPU scheduling",
- "Audio streaming buffer",
- "Database index implementation",
- "Traffic light control system"
- ],
- correctAnswer: 2,
- explanation: "Database indexes typically use tree structures rather than circular queues."
- },
- {
- question: "What happens when you try to enqueue to a full circular queue?",
- options: [
- "It automatically resizes",
- "It overwrites the oldest element",
- "It throws an overflow error/exception",
- "It converts to a linear queue"
- ],
- correctAnswer: 2,
- explanation: "Standard implementations would indicate an overflow condition when trying to enqueue to a full queue."
- },
- {
- question: "How many elements can a circular queue of size N actually hold?",
- options: [
- "N",
- "N-1",
- "N/2",
- "log N"
- ],
- correctAnswer: 1,
- explanation: "Due to the empty slot needed to distinguish full/empty states, maximum capacity is N-1."
- },
- {
- question: "What is the time complexity of peekFront() in a circular queue?",
- options: [
- "O(1)",
- "O(n)",
- "O(log n)",
- "O(n²)"
- ],
- correctAnswer: 0,
- explanation: "All basic operations (enqueue, dequeue, peek) are O(1) in a circular queue."
- },
- {
- question: "Which pointer adjustment is correct after a dequeue operation?",
- options: [
- "front = (front - 1) % capacity",
- "front = (front + 1) % capacity",
- "rear = (rear + 1) % capacity",
- "No pointer change occurs"
- ],
- correctAnswer: 1,
- explanation: "The front pointer moves forward (with wrap-around) after a dequeue: front = (front + 1) % capacity."
- },
- {
- question: "In a circular queue implementation, what does front = -1 indicate?",
- options: [
- "The queue is full",
- "The queue is empty",
- "The queue needs resizing",
- "An error has occurred"
- ],
- correctAnswer: 1,
- explanation: "front = -1 (or similar sentinel value) typically indicates an empty queue state."
- },
- {
- question: "Which real-world scenario best demonstrates circular queue behavior?",
- options: [
- "A stack of plates",
- "A roller coaster with limited seats",
- "A vending machine's product rows",
- "A revolving sushi bar conveyor"
- ],
- correctAnswer: 3,
- explanation: "A sushi conveyor exemplifies circular behavior where empty slots are reused as plates circulate."
+ question: "What is the time complexity of peekFront() in a circular queue?",
+ options: [
+ "O(1)",
+ "O(n)",
+ "O(log n)",
+ "O(n²)"
+ ],
+ correctAnswer: 0,
+ explanation: "All basic operations (enqueue, dequeue, peek) are O(1) in a circular queue."
}
-];
+ ];
const [currentQuestion, setCurrentQuestion] = useState(0);
const [selectedAnswer, setSelectedAnswer] = useState(null);
@@ -144,13 +68,10 @@ const questions = [
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;
@@ -160,18 +81,9 @@ const questions = [
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);
-
if (currentQuestion < questions.length - 1) {
setCurrentQuestion(currentQuestion + 1);
setSelectedAnswer(null);
@@ -186,7 +98,6 @@ const questions = [
};
const handlePreviousQuestion = () => {
- setShowExplanation(false);
setCurrentQuestion(currentQuestion - 1);
setSelectedAnswer(answers[currentQuestion - 1]);
};
@@ -198,38 +109,30 @@ const questions = [
setShowResult(false);
setQuizCompleted(false);
setAnswers(Array(questions.length).fill(null));
- setShowExplanation(false);
setShowIntro(true);
- setPenaltyApplied(false);
};
const calculateWeakAreas = () => {
const weakAreas = [];
if (answers[0] !== questions[0].correctAnswer) {
- weakAreas.push("understanding the basic principle of Selection Sort");
+ weakAreas.push("understanding circular queue advantages");
}
if (answers[1] !== questions[1].correctAnswer) {
- weakAreas.push("time complexity analysis");
+ weakAreas.push("pointer arithmetic in circular queues");
}
if (answers[2] !== questions[2].correctAnswer) {
- weakAreas.push("counting swaps in Selection Sort");
+ weakAreas.push("full/empty conditions");
}
if (answers[3] !== questions[3].correctAnswer) {
- weakAreas.push("comparison with other simple sorts");
+ weakAreas.push("circular queue implementation details");
}
if (answers[4] !== questions[4].correctAnswer) {
- weakAreas.push("space complexity");
- }
- if (answers[5] !== questions[5].correctAnswer) {
- weakAreas.push("stability characteristics");
- }
- if (answers[6] !== questions[6].correctAnswer) {
- weakAreas.push("practical applications");
+ weakAreas.push("time complexity analysis");
}
return weakAreas.length > 0
? `Focus on improving: ${weakAreas.join(', ')}. Review the corresponding sections above.`
- : "Perfect! You've mastered all Selection Sort concepts!";
+ : "Perfect! You've mastered all Circular Queue concepts!";
};
const startQuiz = () => {
@@ -246,22 +149,22 @@ const questions = [
};
return (
-
+
{showIntro ? (
-
-
+
- Queue Quiz Challenge
+ Circular Queue Quiz
-
+
How it works:
@@ -296,14 +199,14 @@ const questions = [
-
-
-
-
+
{questions[currentQuestion].question}
-
+
{questions[currentQuestion].options.map((option, index) => (
- handleAnswerSelect(index)}
>
-
+
{String.fromCharCode(65 + index)}
{option}
@@ -378,32 +277,9 @@ const questions = [
))}
-
- {selectedAnswer !== null && (
-
-
-
- {showExplanation && (
-
- {questions[currentQuestion].explanation}
-
- )}
-
-
- )}
+
-
+
-
+
@@ -438,84 +313,62 @@ const questions = [
{[...Array(5)].map((_, i) => (
-
))}
-
+
- {score === questions.length
- ? "Perfect Score!"
- : score >= questions.length * 0.8
- ? "Excellent Work!"
- : score >= questions.length * 0.6
- ? "Good Job!"
- : score >= questions.length * 0.4
- ? "Keep Practicing!"
- : "Let's Review Again!"}
+ {score === questions.length ? "Perfect Score!" :
+ score >= questions.length * 0.8 ? "Excellent Work!" :
+ score >= questions.length * 0.6 ? "Good Job!" :
+ score >= questions.length * 0.4 ? "Keep Practicing!" : "Let's Review Again!"}
- You scored {((score / questions.length) * 100).toFixed(0)}%
- correct
+ You scored {((score / questions.length) * 100).toFixed(0)}% correct
-
+
Performance Analysis
{calculateWeakAreas()}
-
+
-
- Question Breakdown:
-
+ Question Breakdown:
{questions.map((q, index) => (
-
-
- {q.question}
-
-
+
+ {q.question}
+
{answers[index] === q.correctAnswer ? (
) : (
)}
-
- Your answer:{" "}
- {answers[index] !== null
- ? q.options[answers[index]]
- : "Not answered"}
-
+ Your answer: {answers[index] !== null ? q.options[answers[index]] : "Not answered"}
{answers[index] !== q.correctAnswer && (
-
- Correct answer: {q.options[q.correctAnswer]}
-
+ Correct answer: {q.options[q.correctAnswer]}
)}
))}
-
+
{paragraph[1]}
@@ -232,6 +255,35 @@ const content = () => {+ Queue +
++ Circular Queue +
++ Test Your Knowledge before moving forward! +
+
+ - Queue Quiz Challenge + Circular Queue Quiz
-
How it works:
@@ -296,14 +199,14 @@ const questions = [
- {score === questions.length - ? "Perfect Score!" - : score >= questions.length * 0.8 - ? "Excellent Work!" - : score >= questions.length * 0.6 - ? "Good Job!" - : score >= questions.length * 0.4 - ? "Keep Practicing!" - : "Let's Review Again!"} + {score === questions.length ? "Perfect Score!" : + score >= questions.length * 0.8 ? "Excellent Work!" : + score >= questions.length * 0.6 ? "Good Job!" : + score >= questions.length * 0.4 ? "Keep Practicing!" : "Let's Review Again!"}
- You scored {((score / questions.length) * 100).toFixed(0)}% - correct + You scored {((score / questions.length) * 100).toFixed(0)}% correct
Performance Analysis
{calculateWeakAreas()}
- Question Breakdown: -
+Question Breakdown:
{questions.map((q, index) => ( -- {q.question} -
-{q.question}
+- Your answer:{" "} - {answers[index] !== null - ? q.options[answers[index]] - : "Not answered"} -
+Your answer: {answers[index] !== null ? q.options[answers[index]] : "Not answered"}
{answers[index] !== q.correctAnswer && ( -- Correct answer: {q.options[q.correctAnswer]} -
+Correct answer: {q.options[q.correctAnswer]}
)}