/*Function for adding row The spreadsheet is iterated till the position where the row is to be added. insert() is called to insert a row above the row values in user input. If the row is added to first position (0th position), head pointer is adjusted to point the row which is just inserted. */ void addRow(LList<LList<Cell*>>& rows, int addRowValue){ int h = 0; //increments to track the height or row value LList<Cell*> empty; //create an empty LinkedList of Cell type for (LList<LList<Cell*>>::iterator I = rows.begin(); I != rows.end(); I++){ /*Insert a cell on the position if the value of the rows iterated equals to the value of row in the user input where the row is to be inserted */ if (h == addRowValue) { for (LList<Cell*>::iterator J = (*I).begin(); J != (*I).end(); J++) { I = rows.insert(I, empty, addRowValue); //inserts a Cell in first column (0th column) at specific row position //Push backs empty LList at the back of the First cell till the width of column (last column) for (int k = 0; k < width; k++){ (*I).push_back(new Cell()); } break; } } h++; } //increase the height of the spreadsheet if a row is added height += 1; }
/*Function for removing the row The spreadsheet is iterated till the position where the row is to be removed. remove() is called to remove a row at the row value position in user input. If last row is removed, tail pointer is adjusted and made to point the row above it. If first row (0th row) is removed, head pointer is adjusted adjusted to point next row. */ void removeRow(LList<LList<Cell*>>& rows, int removeRowValue){ int h = 0; //increments to track the height or row value LList<LList<Cell*>>::iterator I = rows.begin(); for (LList<LList<Cell*>>::iterator I = rows.begin(); I != rows.end(); I++){ /*Remove a cell on the position if the value of the rows iterated equals to the value of row in the user input where the row is to be removed. */ if (h == removeRowValue){ I = rows.erase(I, removeRowValue, height); } h++; } //decrease the height of the spreadsheet by one if a row is removed height -= 1; }
void Foam::LList<LListBase, T>::operator=(const LList<LListBase, T>& lst) { this->clear(); for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter) { append(iter()); } }
Foam::LList<LListBase, T>::LList(const LList<LListBase, T>& lst) : LListBase() { for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter) { append(iter()); } }
int main() { LList<int> llist; LList<int>::iterator it = llist.begin(); LList<int>::iterator it2 = llist.end(); it2 = LList<int>::iterator(it); #if 1 it = llist.insert(it,1); it = llist.insert(it,2); it = llist.insert(it,3); it = llist.begin(); cout<<"--------insert-------------"<<endl; for(;it != llist.end();it++) cout<<*it<<endl; llist.clear(); llist.push_back(11); llist.push_back(12); llist.push_back(13); llist.erase(llist.begin()); cout<<"--------push_back-------------"<<endl; for(it=llist.begin();it != llist.end();it++) cout<<*it<<endl; llist.clear(); cout<<"--------size-------------"<<llist.size()<<endl; llist.push_back(14); llist.push_back(15); llist.push_back(16); for(it=llist.begin();it != llist.end();it++) cout<<*it<<endl; cout<<"--------transfer-------------"<<llist.size()<<endl; LList<int>::iterator first= ++llist.begin(); LList<int>::iterator last= llist.end(); llist.transfer(++llist.begin(),++first,last); for(it=llist.begin();it != llist.end();it++) cout<<*it<<endl; cout<<"--------reverse-------------"<<llist.size()<<endl; llist.reverse(); for(it=llist.begin();it != llist.end();it++) cout<<*it<<endl; #endif return 0; }
/*Printing list The spreadsheet is iterated over height and width. The value to be printed is obtained using toString(). toString() returns the values of each cell in string format. */ void printList(LList<LList<Cell*>>& rows){ for (LList<LList<Cell*>>::iterator I = rows.begin(); I != rows.end(); I++) { for (LList<Cell*>::iterator J = (*I).begin(); J != (*I).end(); J++) { if (*J == (*I).back()){ std::cout << (*J)->toString(); } else{ std::cout << (*J)->toString() << ","; } } std::cout << '\n'; } }
/*Replacing Base cell by numeric cell/ string cell/ function cell Empty spreadsheet has each element of Cell type, which is replaced by numericCell/stringCell/ functionalCell based on the input arguments. Input Areguments: 1) "number" -> numericCell 2) "string" -> stringCell 3) "max/min/mean" -> functionalCell */ void insertNewCell(LList<LList<Cell*>>& rows, std::string& command, int column, int row, std::istringstream& ss, std::string& commandType){ int h = 0; for (LList<LList<Cell*>>::iterator I = rows.begin(); I != rows.end(); I++) { h++; //keeps the track of Iteration over height or number of rows int w = 0; //keeps the track of Iteration over width or number of columns and always sets to 0 for new row for (LList<Cell*>::iterator J = (*I).begin(); J != (*I).end(); J++){ w++; /*If row and column iterated equals to the value of row and column in user input, compare the type of cell to be inserted (numericCell/stringCell/functionalCell) */ if (h == row && w == column){ //If user input command is string type, create stringCell on that particular position if (commandType == "string"){ delete *J; *J = new stringCell(command); } //If user input command is number type, create numericCell on that particular position else if (commandType == "number"){ //Trying to convert String type into Double type. Throws Exception if unsuccessful try{ double val = std::stod(std::string(command)); delete *J; *J = new numericCell(val); /* Always calls updateSheet function after every number insertion/updation and modify the value of functionCell if dependent. */ updateSheet(&rows); } catch (std::exception e){ std::cout << "Error: Bad input for set number\n"; } } /*If user input command is max/min/mean type, create functionalCell on that particular position implementing max/min/mean function */ else if (commandType == "max" || commandType == "min" || commandType == "mean"){ try{ double rowValue = std::stod(std::string(command)); int beginOffset = 0, endOffset = 0; ss >> beginOffset >> endOffset; double fVal = 0; functionCell(fVal, &rows, row, column, rowValue, beginOffset, endOffset, commandType); } catch (std::exception e){ std::cout << "Error\n"; } } } } } /* Calls updateSheet() after every insertion so as to update if two functioncells are dependent on each other. */ updateSheet(&rows); }