zoukankan      html  css  js  c++  java
  • 第三章学习小结

    
    

    第三章的主要内容

    1.栈和队列的定义和特点

    2.栈的表示和操作的实现

    3.队列的的表示和操作的实现

    逻辑结构:一对一

    存储结构:顺序栈、链栈

    运算规则:后进先出

    队列

    逻辑结构:一对一

    存储结构:顺序队、链队

    运算规则:先进先出

    4.比较重点的操作有

     判断栈满                                                                          

    bool StackFull(SqStack &S)                                   

    {                        

               if (S.top==S.stacksize) 

              return true;

                else return false;

    }

    入栈

    void Push(SqStack &S, SElemType e) 

    {

              S.data[S.top] = e;

              S.top++;

    }

    5老师提到比较重要的点:

    a.一般头指针与栈顶指针合二为一 由于只能在链表头部进行操作,因此利用链表的头指针作为栈顶是最方便的。故不需要设置头结点(链表中的第一个结点。一般用于单链表,从第二个结点开始存放数据)

    b.使用栈来实现递归:

    在前行阶段,每发生递归,函数的局部变量+参数值+返回地址 入栈。在退回阶段,栈顶的 局部变量+参数值+返回地址 出栈,用于返回调用层次中执行代码的其余部分,即恢复到调用时的状态,继续往下执行。

    6.作业实践中遇到的问题

    在7-1 银行业务队列简单模拟中

    int main()
    {
    	int N,e,f;
    	SqQueue A;
    	SqQueue B;
        InitQueue(A);
        InitQueue(B);
        cin>>N; 
    	for (int i = 0; i < N; i++)
    	{
    		cin>> e;
    		if (e % 2 != 0)
    		{
    		EnQueue(A,e);
    		}
            else
            {
            EnQueue(B,e);
    		}
    	}
    	
    	while((A.front!=A.rear)&&(B.front!=B.rear))
    	{
    		DeQueue(A,f);
            cout<<f<<" ";
    		DeQueue(A,f);
    	    cout<<f<<" ";
    		DeQueue(B,f);
    	    cout<<f<<" ";
    	}
    	
    	while(A.front!=A.rear)
    	{
    		DeQueue(A,f);
    	    cout<<f<<" ";
    	}
        while(B.front!=B.rear)
    	{
    		DeQueue(B,f);
    	    cout<<f<<" ";
    	}
    	return 0;
    }
    

      尝试使用该方法,但最终格式错误;在询问同学的帮助下,灵活运用if和for语句才写出

    while((A.front!=A.rear)&&(B.front!=B.rear))
        {
            if(A.front!=A.rear)
            {
            DeQueue(A,f);
            cout<<f<<" ";
            }
            if(A.front==A.rear)
            break;
            if(A.front!=A.rear)
            {
            DeQueue(A,f);
            cout<<f<<" ";
             }
             if(A.front==A.rear)
            break;
            DeQueue(B,f);
            cout<<f<<" ";
            if(B.front==B.rear)
            break;
            
        }
        for(;length(A)!=0;)
        {
    
        if(length(A)>1)
        {
            DeQueue(A,f);
            cout<<f<<" ";
        }
        else
        {
            DeQueue(A,f);
            cout<<f;
        }
        }
        for(;length(B)!=0;)
        {
    
        if(length(B)>1)
        {
            DeQueue(B,f);
            cout<<f<<" ";
        }
        else
        {
            DeQueue(B,f);
            cout<<f;
        }
        }
        return 0;
    }

    7.上次博客说了许多要多打代码,但由于近期事情比较多,很多时间都用在别的地方没有认真地巩固与复习,并付诸于实践,以后尽量在假期把该学习的该敲的代码都补回来

  • 相关阅读:
    circle
    pq
    graph
    matrix
    计数(count)
    想象一下(imagine)
    出租车(taxi)
    字符串函数 (strfun)
    Sabota?
    3973: seq
  • 原文地址:https://www.cnblogs.com/gwpsf/p/10631793.html
Copyright © 2011-2022 走看看