Skip to content

included the correct header file and define the algo::Stack class. #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions queue_problems/queueDemo.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
#include <iostream>
#include "../include/queue.h"
#include "../include/generic.h"
#include <queue>
#include <cstdlib>
#include <ctime>

// 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<unsigned int>(time(nullptr))); // Seed the random number generator
first = false;
}
return min + rand() % ((max + 1) - min);
}
}


int main()
{
const int QUEUE_SIZE = 10;
algo::Queue<int> Q(QUEUE_SIZE);

std::queue<int> Q;
std::cout << "Pushing following values to queue:\n";
for ( int i = 0; i < QUEUE_SIZE; ++i )
{
Expand All @@ -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;
}
}
8 changes: 4 additions & 4 deletions stack_problems/stackDemo.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include <iostream>
#include <stack.h>
#include <stack>

int main()
{
algo::Stack<double> st{10};
std::stack<double> 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();
Expand All @@ -19,4 +19,4 @@ int main()

std::cout << std::endl;
return 0;
}
}