From 3ddac176042f79e490c05feee0f6679805b326d5 Mon Sep 17 00:00:00 2001 From: chauhanrudra18 Date: Wed, 19 Mar 2025 22:02:47 +0530 Subject: [PATCH 1/2] included the correct header file and define the algo::Stack class. --- stack_problems/stackDemo.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stack_problems/stackDemo.cpp b/stack_problems/stackDemo.cpp index 2b7d804..d0e4e22 100644 --- a/stack_problems/stackDemo.cpp +++ b/stack_problems/stackDemo.cpp @@ -1,13 +1,13 @@ #include -#include +#include int main() { - algo::Stack st{10}; + std::stack st; for ( int i = 0; i < 10; ++i) { st.push( i ); } - st.print(); + // st.print(); // std::stack does not have a print method while (!st.empty()) { std::cout << st.top() << " "; st.pop(); @@ -19,4 +19,4 @@ int main() std::cout << std::endl; return 0; -} +} \ No newline at end of file From deaf1d18aede4c33b58d776139948029352bdd0b Mon Sep 17 00:00:00 2001 From: chauhanrudra18 Date: Wed, 19 Mar 2025 22:37:25 +0530 Subject: [PATCH 2/2] CORRECT HEADER FILE INCLUDED AND THE INCORRECT LINE REMOVED --- queue_problems/queueDemo.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/queue_problems/queueDemo.cpp b/queue_problems/queueDemo.cpp index 386c46d..5495fab 100644 --- a/queue_problems/queueDemo.cpp +++ b/queue_problems/queueDemo.cpp @@ -1,13 +1,25 @@ #include -#include "../include/queue.h" -#include "../include/generic.h" +#include +#include +#include + +// Function to generate random numbers in a range +namespace algo { + int random_range(int min, int max) { + static bool first = true; + if (first) { + srand(static_cast(time(nullptr))); // Seed the random number generator + first = false; + } + return min + rand() % ((max + 1) - min); + } +} int main() { const int QUEUE_SIZE = 10; - algo::Queue Q(QUEUE_SIZE); - + std::queue Q; std::cout << "Pushing following values to queue:\n"; for ( int i = 0; i < QUEUE_SIZE; ++i ) { @@ -16,12 +28,12 @@ int main() Q.push(rand_value); } std::cout << std::endl; - std::cout << "Size of Queue is :" << Q.count() << std::endl; - std::cout << "\nPopping queue values :\n"; + // std::cout << "Size of Queue is :" << Q.count() << std::endl; // Incorrect line, removed + std::cout << "Size of Queue is :" << Q.size() << std::endl; while ( !Q.empty() ) { std::cout << Q.front() << " "; Q.pop(); } std::cout << std::endl; return 0; -} +} \ No newline at end of file