本文整理汇总了C++中LList::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ LList::begin方法的具体用法?C++ LList::begin怎么用?C++ LList::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LList
的用法示例。
在下文中一共展示了LList::begin方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addRow
/*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;
}
示例2: removeRow
/*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;
}
示例3: main
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;
}
示例4: printList
/*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';
}
}
示例5: insertNewCell
/*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);
}