Library 2

myTests completed
This commit is contained in:
Alessandro Ferro 2021-04-21 23:37:01 +02:00
parent c06eac8429
commit 9c17978640
3 changed files with 107 additions and 10 deletions

Binary file not shown.

View File

@ -85,29 +85,34 @@ void UseChosenType(DataStructure chosenDataStructure, DataType chosenDataType, I
if(chosenDataType == DataType::integer){
StackVec<int> stckvec;
stckvec = generateRandomStackVecInt();
StackIntFunctions(stckvec);
StackFunctions(stckvec);
}
else if(chosenDataType == DataType::ffloat){
StackVec<float> stckvec;
stckvec = generateRandomStackVecFloat();
StackFunctions(stckvec);
}
else if(chosenDataType == DataType::sstring){
StackVec<std::string> stckvec;
stckvec = generateRandomStackVecString();
StackFunctions(stckvec);
}
}
else if(chosenImplementation == Implementation::list){
if(chosenDataType == DataType::integer){
StackLst<int> stcklst;
stcklst = generateRandomStackLstInt();
StackFunctions(stcklst);
}
else if(chosenDataType == DataType::ffloat){
StackLst<float> stcklst;
stcklst = generateRandomStackLstFloat();
StackFunctions(stcklst);
}
else if(chosenDataType == DataType::sstring){
StackLst<std::string> stcklst;
stcklst = generateRandomStackLstString();
StackFunctions(stcklst);
}
}
}
@ -116,35 +121,41 @@ void UseChosenType(DataStructure chosenDataStructure, DataType chosenDataType, I
if(chosenDataType == DataType::integer){
QueueVec<int> queuevec;
queuevec = generateRandomQueueVecInt();
QueueFunctions(queuevec);
}
else if(chosenDataType == DataType::ffloat){
QueueVec<float> queuevec;
queuevec = generateRandomQueueVecFloat();
QueueFunctions(queuevec);
}
else if(chosenDataType == DataType::sstring){
QueueVec<std::string> queuevec;
queuevec = generateRandomQueueVecString();
QueueFunctions(queuevec);
}
}
else if(chosenImplementation == Implementation::list){
if(chosenDataType == DataType::integer){
QueueLst<int> queuelist;
queuelist = generateRandomQueueListInt();
QueueFunctions(queuelist);
}
else if(chosenDataType == DataType::ffloat){
QueueLst<float> queuelist;
queuelist = generateRandomQueueListFloat();
QueueFunctions(queuelist);
}
else if(chosenDataType == DataType::sstring){
QueueLst<std::string> queuelist;
queuelist = generateRandomQueueListString();
QueueFunctions(queuelist);
}
}
}
}
template <typename T>
void StackIntFunctions(T& stk){
void StackFunctions(T& stk){
unsigned short int choice;
do{
std::cout<<std::endl<<std::endl;
@ -163,7 +174,7 @@ void StackIntFunctions(T& stk){
std::cout<<std::endl;
switch(choice){
case 1:
PushInt(stk);
Push(stk);
break;
case 2:
Pop(stk);
@ -183,13 +194,87 @@ void StackIntFunctions(T& stk){
case 7:
Clear(stk);
break;
case 8:
menu();
break;
}
}while(choice!=9 && choice!=8);
}
template <typename T>
void PushInt(T& stk){
int element;
void QueueFunctions(T& queue){
unsigned short int choice;
do{
std::cout<<std::endl<<std::endl;
std::cout<<"Choose one of the following options:"<<std::endl;
std::cout<<"1. Inserimento di un elemento (Enqueue)"<<std::endl;
std::cout<<"2. Rimozione di un elemento (Dequeue)"<<std::endl;
std::cout<<"3. Rimozione con lettura (HeadNDequeue)"<<std::endl;
std::cout<<"4. Lettura non distruttiva (Head)"<<std::endl;
std::cout<<"5. Test di vuotezza"<<std::endl;
std::cout<<"6. Dimensione"<<std::endl;
std::cout<<"7. Clear Stack"<<std::endl;
std::cout<<"8. Vai indietro"<<std::endl;
std::cout<<"9. Esci"<<std::endl;
std::cin>>std::ws;
std::cin>>choice;
std::cout<<std::endl;
switch(choice){
case 1:
Enqueue(queue);
break;
case 2:
Dequeue(queue);
break;
case 3:
HeadNDequeue(queue);
break;
case 4:
Head(queue);
break;
case 5:
Empty(queue);
break;
case 6:
Size(queue);
break;
case 7:
Clear(queue);
break;
case 8:
menu();
break;
}
}while(choice!=9 && choice!=8);
}
template <template <typename...> class C, typename T>
void Enqueue(C<T>& queue){
T element;
std::cout<<"Element to enqueue: ";
std::cin>>std::ws;
std::cin>>element;
queue.Enqueue(element);
}
template <typename T>
void Dequeue(T& queue){
queue.Dequeue();
}
template <typename T>
void HeadNDequeue(T& queue){
std::cout<<"The head and dequeued element is "<<queue.HeadNDequeue();
}
template <typename T>
void Head(T& queue){
std::cout<<"The head is "<<queue.Head();
}
template <template <typename...> class C, typename T>
void Push(C<T>& stk){
T element;
std::cout<<"Element to push: ";
std::cin>>std::ws;
std::cin>>element;
@ -213,7 +298,7 @@ void Top(T& stk){
template <typename T>
void Empty(T& stk){
std::cout<<"Stack is ";
std::cout<<"It is ";
stk.Empty()? std::cout<<"" : std::cout<<"not ";
std::cout<<"empty";
}
@ -226,7 +311,7 @@ void Size(T& stk){
template <typename T>
void Clear(T& stk){
stk.Clear();
std::cout<<"Stack has been cleared.";
std::cout<<"It has been cleared.";
}

View File

@ -36,10 +36,10 @@ lasd::StackVec<float> generateRandomStackVecFloat();
lasd::StackVec<std::string> generateRandomStackVecString();
template <typename T>
void StackIntFunctions(T&);
void StackFunctions(T&);
template <typename T>
void PushInt(T&);
template <template <typename...> class C, typename T>
void Push(C<T>&);
template <typename T>
void Pop(T&);
template <typename T>
@ -52,6 +52,18 @@ template <typename T>
void Size(T&);
template <typename T>
void Clear(T&);
template <typename T>
void QueueFunctions(T&);
template <template <typename...> class C, typename T>
void Enqueue(C<T>&);
template <typename T>
void Dequeue(T&);
template <typename T>
void HeadNDequeue(T&);
template <typename T>
void Head(T&);
std::string generateRandomString(ulong);
ulong getDimension();