Skip to content
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

Issue#304 #5

Open
wants to merge 1 commit into
base: main
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
48 changes: 48 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file, it's generated by VSCode and not necessary for the repo

"files.associations": {
"*.tcc": "cpp",
"typeinfo": "cpp",
"iostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp"
}
}
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
CC=g++
PROJ=welcome
Que=paneraQueue

release: $(PROJ).cpp
$(CC) -O2 -o $(PROJ) -std=c++17 $+
release: $(PROJ).cpp $(Que).cpp
$(CC) -O2 -o program -std=c++17 $+

debug: $(PROJ).cpp
debug: $(PROJ).cpp $(Que).cpp
$(CC) -g -o $(PROJ)_$@ -std=c++17 $+
$(CC) -g -o $(Que)_$@ -std=c++17 $+

clean:
rm -v $(PROJ) $(PROJ)_debug
rm -v program
rm -v *.o
rm -v *_debug

43 changes: 43 additions & 0 deletions magic_numbers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>

class magicNumbers{
public:
magicNumbers(int seed) : seed(seed){
init();
}
void reconfigure(int seed){
this->seed = seed;
init();
}
int generate(int n){
switch((rand() + n) % 10){
case 1:
case 2:
return 5;
case 5:
return 3;
case 6:
return 1;
case 4:
case 10:
return 4;
case 9:
return 1;
case 7:
return 2;
case 3:
return 10;
default:
break;

}
return 7;
}


private:
int seed;
void init(){
srand(7);
}
};
76 changes: 76 additions & 0 deletions paneraQueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <iostream>
#include "paneraQueue.hpp";

using namespace std;

template<class T>
paneraQueue<T>::paneraQueue(int n){
counter = n;
}

template<class T>
void paneraQueue<T>::push(T const& value){
Node* loser = new Node(value, counter++);
if (!head) {
head = loser;
tail = head;
}
else {
tail->setNext(loser);
tail = tail->getNext();
}
}

bool isOdd(int n){
switch (n % 10){
case 1:
case 3:
case 5:
case 7:
case 9:
return false;
default:
return true;
}
}

template<class T>
T paneraQueue<T>::peek(){
int m = rng.generate(4);
if (m < 0){
cout << ":(\n";
}
Node* temp = head;
if (!head) return NULL;
for (int i = 0; i < m; i++){
temp = temp->getNext();
if (temp == nullptr) break;
}
return temp->getVal();
}

template<class T>
void paneraQueue<T>::pop(){
int m = rng.generate(4);
if (m < 0){
cout << ":(\n";
}
Node* temp = head;
Node* anotherTemporaryNode = head->getNext();
if (!head->getNext()) return;
for (int i = 0; i < m; i++){
temp = temp->getNext();
anotherTemporaryNode = anotherTemporaryNode->getNext();
if (anotherTemporaryNode == nullptr) break;
}
temp->setNext(anotherTemporaryNode->getNext());
delete anotherTemporaryNode;
}

template<class T>
bool paneraQueue<T>::find(const T & value){
int m = rng.generate(4);
return (isOdd(m));
}

template class paneraQueue<char>;
46 changes: 46 additions & 0 deletions paneraQueue.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "magic_numbers.hpp";

using namespace std;

template <class T>
class paneraQueue{
public:
class Node{
public:
Node(char name, int val){
this->name = val;
this->val = name;
next = nullptr;
}
Node(char name, int val, Node* prev){
this->name = val;
this->val = name;
next = prev;
}
Node * getNext(){
return this->next;
}
void setNext(Node * nex){
this->next = nex;
}
char getVal(){
return val;
}
private:
char val;
int name;
Node* next;
};
paneraQueue(int n);
void push(T const& value);
T peek();
void pop();
bool find(const T & value);

private:
Node* head = nullptr;
Node* tail = nullptr;
int seed = 0;
int counter;
magicNumbers rng = *(new magicNumbers(time_t(0)));
};
35 changes: 34 additions & 1 deletion welcome.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
#include <iostream>
#include "paneraQueue.hpp"

void init(paneraQueue<char> &q){
q.push('A');
q.push('B');
q.push('D');
q.push('E');
q.push('F');
q.push('G');
q.push('U');
q.push('I');
q.push('J');
q.push('L');
q.push('O');
q.push('N');
}

void printBlue(paneraQueue<char> &PQ){
init(PQ);
magicNumbers rng = magicNumbers(0);
for (int i = 0; i < 2; i++){
std::cout << PQ.peek();
PQ.pop();
}
std::cout << " ";
for (int i = 0; i < 3; i++){
std::cout << PQ.peek();
PQ.pop();
}
std::cout << "E!" << std::endl;
}

int main(int argc, char *argv[]) {
std::cout << " \
Expand Down Expand Up @@ -29,4 +60,6 @@ int main(int argc, char *argv[]) {
.:lllll:. .cllllc, \n" << std::endl;
std::cout << "Hello from Michigan Hackers!\n";
std::cout << "Learn more: https://www.youtube.com/watch?v=dQw4w9WgXcQ" << std::endl;
}
paneraQueue<char> PQ(0);
printBlue(PQ);
}