Library 5

bugfix
This commit is contained in:
Alessandro Ferro 2021-06-02 11:50:40 +02:00
parent 828ec16447
commit 58699b7d2e
2 changed files with 38 additions and 45 deletions

View File

@ -140,28 +140,32 @@ void MatrixCSR<Data>::ColumnResize(const ulong& new_column_size){
Clear(); Clear();
} }
else if(new_column_size < columns){ else if(new_column_size < columns){
Node** last; Node** prev;
Node** last_not_deleted;
Node* toDelete; Node* toDelete;
Node** toModify;
for(ulong i=0 ; i<R.Size()-1 ; ++i){ // iterate over the R array for(ulong i=0 ; i<R.Size()-1 ; ++i){ // iterate over the R array
last = R[i+1]; prev = R[i]; // in case an element must be deleted, this is its previous element.
last_not_deleted = R[i];
for(Node** ptr = R[i] ; ptr!=R[i+1] ; ptr = &( (*(*ptr)).next ) ){ for(Node** ptr = R[i] ; ptr!=R[i+1] ; ){
if(((*ptr)->value).second < new_column_size){ if(((*ptr)->value).second < new_column_size){
last_not_deleted = &( (*(*ptr)).next ); prev = &( (*(*ptr)).next );
ptr = &( (*(*ptr)).next);
}else{ }else{
std::cout<<"\n\nSto cancellando "<<((*ptr)->value).first<<"\n\n";
toDelete = *ptr; toDelete = *ptr;
toModify = &( (*(*ptr)).next );
*ptr = (*(*ptr)).next; *ptr = (*(*ptr)).next;
delete toDelete; delete toDelete;
--size; --size;
//debug();
for(ulong j=i+1 ; j<R.Size() ; ++j){ for(ulong j=i+1 ; j<R.Size() ; ++j){
if(R[j] == last){ if(R[j] == toModify){
R[j] = last_not_deleted; R[j] = prev;
} }
else break; else break;
} }
if(ptr == R[i+1]) break;
} }
} }
} }
@ -270,26 +274,27 @@ void MatrixCSR<Data>::FoldPostOrder(const typename FoldableContainer<Data>::Fold
template <typename Data> template <typename Data>
void MatrixCSR<Data>::debug(){ void MatrixCSR<Data>::debug(){
std::cout<<std::endl; std::cout<<std::endl;
std::cout<<"rows: "<<rows<<" columns: "<<columns<<" size: "<<size<<"\n\n";
Node* tmp = head;
while(tmp!=nullptr){ // std::cout<<"rows: "<<rows<<" columns: "<<columns<<" size: "<<size<<"\n\n";
std::cout<<(tmp->value).first<<"|"<< (tmp->value).second; // Node* tmp = head;
std::cout<<std::endl; //
std::cout<<&(tmp->next); // while(tmp!=nullptr){
// std::cout<<(tmp->value).first<<"|"<< (tmp->value).second;
std::cout<<std::endl; // std::cout<<std::endl;
std::cout<<std::endl; // std::cout<<&(tmp->next);
//
tmp = tmp->next; // std::cout<<std::endl;
} // std::cout<<std::endl;
//
std::cout << "R VECTOR:" << '\n'; // tmp = tmp->next;
for(ulong i=0; i<R.Size();++i){ // }
std::cout << R[i] << '\n'; //
} // std::cout << "R VECTOR:" << '\n';
std::cout<<std::endl; // for(ulong i=0; i<R.Size();++i){
std::cout<<std::endl; // std::cout << R[i] << '\n';
// }
// std::cout<<std::endl;
// std::cout<<std::endl;
//// print //// print
// for(int i=0; i<rows; ++i){ // for(int i=0; i<rows; ++i){

View File

@ -34,23 +34,11 @@ void menu(){
mat(3,4) = 9; mat(3,4) = 9;
mat(4,1) = 6; mat(4,1) = 6;
mat(4,3) = 7; mat(4,3) = 7;
mat(4,0) = 13;
for(ulong i=0 ; i<mat.RowNumber() ; ++i){ mat.ColumnResize(2);
for(ulong j=0 ; j<mat.ColumnNumber() ; ++j){
cout<<mat(i,j)<<" ";
}
cout<<endl;
}
mat(3,0) = 5;
mat(3,1) = 6;
mat(3,2) = 7;
mat(3,3) = 8;
for(ulong i=0 ; i<mat.RowNumber() ; ++i){ mat.debug();
for(ulong j=0 ; j<mat.ColumnNumber() ; ++j){
cout<<mat(i,j)<<" "; }
}
cout<<endl;
}
}
} }