Library 5

This commit is contained in:
Alessandro Ferro 2021-06-05 14:25:22 +02:00
parent 98f7065258
commit d15173a276
3 changed files with 19 additions and 26 deletions

View File

@ -116,10 +116,7 @@ bool MatrixCSR<Data>::operator!=(const MatrixCSR& toCompare) const noexcept{
template <typename Data>
void MatrixCSR<Data>::RowResize(const ulong& new_row_size){
if(new_row_size == 0){
Clear();
}
else if(new_row_size > rows){
if(new_row_size > rows){
R.Resize(new_row_size+1);
for(ulong i=rows+1 ; i<R.Size(); ++i){
R[i] = R[rows];
@ -143,10 +140,7 @@ void MatrixCSR<Data>::RowResize(const ulong& new_row_size){
template <typename Data>
void MatrixCSR<Data>::ColumnResize(const ulong& new_column_size){
if(new_column_size == 0){
Clear();
}
else if(new_column_size < columns){
if(new_column_size < columns){
Node** prev;
Node* toDelete;
Node** toModify;

View File

@ -70,22 +70,17 @@ bool MatrixVec<Data>::operator!=(const MatrixVec& toCompare) const noexcept{
}
template <typename Data>
void MatrixVec<Data>::RowResize(const ulong& newdim){
if(newdim == 0){
Clear();
}else{
Vector<Data>::Resize(newdim * columns);
rows = newdim;
size = newdim * columns;
void MatrixVec<Data>::RowResize(const ulong& new_row_dim){
if(new_row_dim != rows){
Vector<Data>::Resize(new_row_dim * columns);
rows = new_row_dim;
size = new_row_dim * columns;
}
}
template <typename Data>
void MatrixVec<Data>::ColumnResize(const ulong& new_column_dim){
if(new_column_dim == 0){
Clear();
}
else if(new_column_dim != columns){
if(new_column_dim != columns){
ulong limit = (new_column_dim < columns)? new_column_dim : columns;
Data* tmp = new Data[rows * new_column_dim]{};
for(ulong i=0 ; i<rows ; ++i){

View File

@ -2,7 +2,6 @@
#include <random>
#include <iostream>
void menu(){
DataType chosenDataType;
@ -67,32 +66,38 @@ void UseChosenType(Implementation chosenImplementation, DataType chosenDataType)
if(chosenDataType == DataType::integer){
MatrixVec<int> mtx;
mtx = GenerateIntegerMat(mtx);
cout<<"\nThe matrix has been randomly generated.\n";
IntegerFunctions(mtx);
}else if(chosenDataType == DataType::ffloat){
MatrixVec<float> mtx;
mtx = GenerateFloatMat(mtx);
cout<<"\nThe matrix has been randomly generated.\n";
FloatFunctions(mtx);
}else if(chosenDataType == DataType::sstring){
MatrixVec<string> mtx;
mtx = GenerateStringsMat(mtx);
cout<<"\nThe matrix has been randomly generated.\n";
StringFunctions(mtx);
}
}else if(chosenImplementation == Implementation::yale){
if(chosenDataType == DataType::integer){
MatrixCSR<int> mtx;
mtx = GenerateIntegerMat(mtx);
cout<<"\nThe matrix has been randomly generated.\n";
IntegerFunctions(mtx);
}else if(chosenDataType == DataType::ffloat){
MatrixCSR<float> mtx;
mtx = GenerateFloatMat(mtx);
cout<<"\nThe matrix has been randomly generated.\n";
FloatFunctions(mtx);
}else if(chosenDataType == DataType::sstring){
MatrixCSR<string> mtx;
mtx = GenerateStringsMat(mtx);
cout<<"\nThe matrix has been randomly generated.\n";
StringFunctions(mtx);
}
}
@ -524,7 +529,6 @@ T GenerateStringsMat(T& mat){
}while(column >= n_columns);
matrix(row,column) = generateRandomString(dist(gen));
}
return matrix;
}