试图清除arraystack并得到分段错误?

所以从这里开始。 我没有足够的经验,也没有足够的时间使它弹出到另一个窗口中来,使其效率更高。

第二,我也没有足够的时间添加其他变量或旋转变量,因为分段错误不是唯一的错误。有时会打印|一无所有,因为下面有一个形状。但是它不会打印出形状。

另外,我必须使用数组堆栈和链表,所以我无法不使用它们2。我要解决的主要问题是,当代码到达明确的row1时,它只会给出分段错误。但是,为什么,我认为我做的一切正确。

Here's rest of my code: https://repl.it/@AbbasZaidi/Final

bool RowFull(ArrayStack<string> &givenRow) {
bool Full=true;
string Given=givenRow.top();
for(int i=0;i<Given.length();i++)
{
    if(isspace(Given[i]))
    {
        Full=false;
    }
};
return Full;
}
void Board1Redo(tetris &a,ArrayStack<string> &bottomrow,ArrayStack<string> &row1,ArrayStack<string> &row2,ArrayStack<string> &row3, ArrayStack<string> &row4, ArrayStack<string> &row5, ArrayStack<string> &row6, ArrayStack<string> &row7, ArrayStack<string> &row8, ArrayStack<string> &row9,string &rowa,string &rowb,string &rowc,string &rowd,string &rowe,string &rowf,string &rowg,string &rowh,string &rowi, string &block1,string &block2,string &check, int &x,int &c) {
            while(!gameOver(row9)){
            x=0;
            cout<<"starting board1Redo"<<endl;
                if(isSpace(row9))
                {
                //rotate(a,block1,block2,c);
                leftOrRight(x);
                for(int i=0;i<13;i++)
                {
                    if(i==x && rowi[x+1]==' ')
                    {

                        rowi[x+1]='|';
                    }
                    if(i==12)
                        rowi[11]='#';
                }
                row9.push(rowi);
                cout<<row9.top()<<endl;

                cout<<row8.top()<<endl;

                cout<<row7.top()<<endl;

                cout<<row6.top()<<endl;

                cout<<row5.top()<<endl;

                cout<<row4.top()<<endl;

                cout<<row3.top()<<endl;

                cout<<row2.top()<<endl;

                cout<<row1.top()<<endl;

                cout<<bottomrow.top()<<endl;

            }
            if(row8.top()==check)
                rowh=check;
            if(!top(rowh[x+1],rowi[x+1]))
            {
                //do it again until it reaches bottom
                //rotate(a,block1,block2,c);
                leftOrRight(x);
                row8.push(rowh);
                for(int i=0;i<13;i++)
                {
                    if(i==x && rowh[x+1]==' ')
                    {
                        rowh[i+1]='|';
                    }

                if(i==12)
                    rowh[11]='#';
                }
                row9.pop();
                cout<<row9.top()<<endl;

                row8.push(rowh);
                cout<<row8.top()<<endl;

                cout<<row7.top()<<endl;

                cout<<row6.top()<<endl;

                cout<<row5.top()<<endl;

                cout<<row4.top()<<endl;

                cout<<row3.top()<<endl;

                cout<<row2.top()<<endl;

                cout<<row1.top()<<endl;

                cout<<bottomrow.top()<<endl;
        }
        if(row7.top()==check)
            rowg=check;
        if(!top(rowg[x+1],rowh[x+1]))
        {
        //do it again until it reaches bottom
        //rotate(a,block1,block2,c);
        leftOrRight(x);
        row7.push(rowg);
        for(int i=0;i<13;i++)
        {
            if(i==x && rowg[x+1]==' ')
            {
                rowg[i+1]='|';
            }

            if(i==12)
                rowg[11]='#';
        }
            cout<<row9.top()<<endl;

            row8.pop();
            cout<<row8.top()<<endl;

            row7.push(rowg);
            cout<<row7.top()<<endl;

            cout<<row6.top()<<endl;

            cout<<row5.top()<<endl;

            cout<<row4.top()<<endl;

            cout<<row3.top()<<endl;

            cout<<row2.top()<<endl;

            cout<<row1.top()<<endl;


            cout<<bottomrow.top()<<endl;
        }
            if(row6.top()==check)
                rowf=check;
            if(!top(rowf[x+1],rowg[x+1]))
            {
                //do it again until it reaches bottom
                //rotate(a,block1,block2,c);
                leftOrRight(x);
                row6.push(rowf);
                for(int i=0;i<13;i++)
                    {
                        if(i==x && rowf[x+1]==' ')
                        {
                            rowf[i+1]='|';
                        }

                        if(i==12)
                            rowf[11]='#';
                    }
                cout<<row9.top()<<endl;

                cout<<row8.top()<<endl;

                row7.pop();
                cout<<row7.top()<<endl;

                row6.push(rowf);
                cout<<row6.top()<<endl;

                cout<<row5.top()<<endl;

                cout<<row4.top()<<endl;

                cout<<row3.top()<<endl;

                cout<<row2.top()<<endl;

                cout<<row1.top()<<endl;

                cout<<bottomrow.top()<<endl;
            }

            if(row5.top()==check)
                rowe=check;
            if(!top(rowe[x+1],rowf[x+1]))
            {
                //do it again until it reaches bottom
                //rotate(a,block1,block2,c);
                leftOrRight(x);
                row5.push(rowe);
                for(int i=0;i<13;i++)
                {
                    if(i==x && rowe[x+1]==' ')
                    {
                        rowe[i+1]='|';
                    }

                    if(i==12)
                        rowe[11]='#';
                }
                cout<<row9.top()<<endl;

                cout<<row8.top()<<endl;

                cout<<row7.top()<<endl;

                row6.pop();
                cout<<row6.top()<<endl;

                row5.push(rowe);
                cout<<row5.top()<<endl;

                cout<<row4.top()<<endl;

                cout<<row3.top()<<endl;

                cout<<row2.top()<<endl;

                cout<<row1.top()<<endl;


                cout<<bottomrow.top()<<endl;
            }

            if(row4.top()==check)
                rowd=check;
            if(!top(rowd[x+1],rowe[x+1]))
            {
                cout<<"now in rowd->rowe"<<endl;
            //do it again until it reaches bottom
            //rotate(a,block1,block2,c);
            leftOrRight(x);
            row4.push(rowd);
            for(int i=0;i<13;i++)
            {
                if(i==x && rowd[x+1]==' ')
                {
                    rowd[i+1]='|';
                }

                if(i==12)
                    rowd[11]='#';
            }
            cout<<row9.top()<<endl;

            cout<<row8.top()<<endl;

            cout<<row7.top()<<endl;

            cout<<row6.top()<<endl;

            row5.pop();
            cout<<row5.top()<<endl;

            row4.push(rowd);
            cout<<row4.top()<<endl;

            cout<<row3.top()<<endl;

            cout<<row2.top()<<endl;

            cout<<row1.top()<<endl;

            cout<<bottomrow.top()<<endl;
            }
            if(row3.top()==check)
                rowc=check;
            if(!top(rowc[x+1],rowd[x+1]))
            {
                cout<<"now in rowc-rowd"<<endl;
                //rotate(a,block1,block2,c);
                leftOrRight(x);
                row3.push(rowc);
                for(int i=0;i<13;i++)
                {
                    if(i==x && rowc[x+1]==' ')
                    {
                        rowc[x+1]='|';
                    }
                     if(i==12)
                        rowc[11]='#';
                }
                cout<<row9.top()<<endl;

                cout<<row8.top()<<endl;

                cout<<row7.top()<<endl;

                cout<<row6.top()<<endl;

                cout<<row5.top()<<endl;

                row4.pop();
                cout<<row4.top()<<endl;

                row3.push(rowc);
                cout<<row3.top()<<endl;

                cout<<row2.top()<<endl;

                cout<<row1.top()<<endl;


                cout<<bottomrow.top()<<endl;
            }
            if(row2.top()==check)
                rowb=check;
            if(!top(rowb[x+1],rowc[x+1]))
            {
                cout<<"now in rowb-rowc"<<endl;
                //rotate(a,block1,block2,c);
                leftOrRight(x);
                row2.push(rowb);
                for(int i=0;i<13;i++)
                {
                    if(i==x && rowb[x+1]==' ')
                    {
                        rowb[x+1]='|';
                    }
                     if(i==12)
                     {
                        rowb[11]='#';
                     }

                }
                cout<<row9.top()<<endl;

                cout<<row8.top()<<endl;

                cout<<row7.top()<<endl;

                cout<<row6.top()<<endl;

                cout<<row5.top()<<endl;

                cout<<row4.top()<<endl;

                row3.pop();
                cout<<row3.top()<<endl;

                row2.push(rowb);
                cout<<row2.top()<<endl;

                cout<<row1.top()<<endl;

                cout<<bottomrow.top()<<endl;
            }
            if(row1.top()==check)
                rowa=check;
            if(!top(rowa[x+1],rowb[x+1]))
            {
                cout<<"now in rowa-rowb"<<endl;
                //rotate(a,block1,block2,c);
                leftOrRight(x);
                for(int i=0;i<13;i++)
                {
                    if(i==x && rowa[x+1]==' ')
                    {
                        rowa[x+1]='|';
                    }
                     if(i==12)
                        rowa[11]='#';
                }
                cout<<row9.top()<<endl;

                cout<<row8.top()<<endl;

                cout<<row7.top()<<endl;

                cout<<row6.top()<<endl;

                cout<<row5.top()<<endl;

                cout<<row4.top()<<endl;

                cout<<row3.top()<<endl;

                row2.pop();
                cout<<row2.top()<<endl;

                row1.push(rowa);
                cout<<row1.top()<<endl;

                cout<<bottomrow.top()<<endl;
            }
            if(!a.isempty())
                a.remove(0);
            else if(a.isempty() && !gameOver(row9))
                a.addingShape();
            if(RowFull(row1))
            {
                cout<<"row1 is full"<<endl;
                row1.clear();
                row1.push("#          #");
            }
            if(RowFull(row2))
            {
                cout<<"row2 is full"<<endl;
                row2.clear();
                row2.push("#          #");
            }
            if(RowFull(row3)) {
            cout<<"row3 is full"<<endl;
                row3.clear();
                row3.push("#          #");
            }
            if(RowFull(row4))
            {
                cout<<"row4 is full"<<endl;
                row4.clear();
                row4.push("#          #");
            }
            if(RowFull(row5))
            {
                cout<<"row5 is full"<<endl;
                row5.clear();
                row5.push("#          #");
            }
            if(RowFull(row6))
            {
                cout<<"row6 is full"<<endl;
                row6.clear();
                row6.push("#          #");
            }
            if(RowFull(row7))
            {
                cout<<"row7 is full"<<endl;
                row7.clear();
                row7.push("#          #");
            }
            if(RowFull(row8))
            {
                cout<<"row8 is full"<<endl;
                row8.clear();
                row8.push("#          #");
            }
            if(RowFull(row9))
            {
                cout<<"row9 is full"<<endl;
                row9.clear();
                row9.push("#          #");
            }
                Board1Redo(a, bottomrow, row1, row2, row3, row4, row5, row6, row7, row8, row9, rowa, rowb,rowc,rowd,rowe,rowf,rowg,rowh,rowi,block1, block2,check, x, c);
        }
    }
评论