• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            把握命運(yùn),追逐夢想

            對自己所做的事要有興趣,同時(shí)還要能夠堅(jiān)持不懈

            統(tǒng)計(jì)

            留言簿(1)

            閱讀排行榜

            評論排行榜

            C++作業(yè)二----實(shí)現(xiàn)一個(gè)棧的基本功能

            #include "Stack.h"

            CStack::CStack(
            void)
            {
                
            this->m_pTopMost = new char[100];
                
            this->m_pBottom = &(this->m_pTopMost[99])+1;
                
            this->m_pTop = this->m_pBottom;
                
            }


            CStack::CStack(CStack 
            &stack)
            {
                
            this->m_pTopMost = new char[100];
                
            this->m_pBottom = &(this->m_pTopMost[99])+1;
                
            this->m_pTop = this->m_pBottom - (stack.m_pBottom - stack.m_pTop);
                memcpy(
            this->m_pTop,stack.m_pTop,this->m_pBottom-this->m_pTop);
            }


            CStack::
            ~CStack(void)
            {
                delete[] m_pTopMost;
            }




            void CStack::reset()
            {
                
            this->m_pBottom = &(this->m_pTopMost[99])+1;
                
            this->m_pTop = m_pBottom;
            }


            void CStack::push(char c)
            {
                
            if(!this->full())
                
            {
                    
            this->m_pTop--;
                    
            *(this->m_pTop) = c;        
                }

                
            else
                
            {
                    cout
            <<"棧已滿"<<endl;
                }

                
            }


            void CStack::push(char c,int n)
            {
                
            for(int i = 0; i < n; i++)
                
            {
                    
            this->push(c);
                }

            }


            char CStack::pop()
            {
                
            if(!this->empty())
                
            {
                    
            char ret= *(this->m_pTop);
                    
            this->m_pTop++;
                    
            return ret;
                }

                
            else
                
            {
                    cout
            <<"棧為空"<<endl;
                    
            return '\0';
                }

            }


            string CStack::pop(int n)
            {
                
            string str="";
                
            for(int i = 0; i < n; i++)
                
            {
                    str
            +=this->pop();
                }

                
            return str;
            }


            char CStack::top()   
            {
                
            return *(this->m_pTop);
            }


            bool CStack::empty()
            {
                
            if(this->m_pTop == this->m_pBottom)
                    
            return true;
                
            else
                    
            return false;
            }


            bool CStack::full()
            {
                
            if(this->m_pTop == this->m_pTopMost)
                    
            return true;
                
            else
                    
            return false;
            }
            #pragma once
            #include
            "stdafx.h"

            class CStack
            {
            public:
                CStack(
            void);
                CStack(CStack
            & stack);
                
            virtual ~CStack(void);

                
            void reset();
                
            void push(char c);
                
            void push(char c,int n);  //連續(xù)壓入n個(gè)字符
                char pop();
                
            string pop(int n);         //連續(xù)彈出n個(gè)字符
                char top();                 //獲得棧頂字符
                bool empty();
                
            bool full();

            private:
                
            char *m_pBottom;
                
            char *m_pTop;
                
            char *m_pTopMost;

            }
            ;
            //stdafx.h
            #pragma once
            #include
            <string>
            #include
            <iostream>
            using namespace std;
            //test.cpp
            #include"stdafx.h"
            #include
            "Stack.h"

            #ifdef   _DEBUG
            #define  SET_CRT_DEBUG_FIELD(a) \
                        _CrtSetDbgFlag((a) 
            | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
            #define  CLEAR_CRT_DEBUG_FIELD(a) \
                        _CrtSetDbgFlag(
            ~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
            #else
            #define  SET_CRT_DEBUG_FIELD(a)   ((void) 0)
            #define  CLEAR_CRT_DEBUG_FIELD(a) ((void) 0)
            #endif

            int main()
            {

                _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
                _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
                _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
                _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
                _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
                _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );

                

                CStack 
            *pStack = new CStack();

                
            char ch[20]="0123456789abcdefghi";

                
            for(int i = 0; i < 19; i++)
                
            {
                    pStack
            ->push(ch[i]);
                }


                pStack
            ->push('Y',10);

                CStack stack2(
            *pStack);

                
            string str = pStack->pop(29);

                cout
            <<str;


                _CrtMemDumpAllObjectsSince( NULL );
                



                
            string str2 = stack2.pop(19);
                cout
            <<str2;

                delete pStack;

                _CrtDumpMemoryLeaks( );

                SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF );

                
            return 0;

            }

            posted on 2009-08-12 17:48 把握命運(yùn) 閱讀(259) 評論(0)  編輯 收藏 引用

            国产精品免费看久久久| 久久亚洲色一区二区三区| 久久99国产精品久久久| 久久综合综合久久97色| 亚洲欧美日韩精品久久亚洲区 | 久久91综合国产91久久精品| 精品视频久久久久| 一本色道久久HEZYO无码| 99精品伊人久久久大香线蕉| 久久强奷乱码老熟女网站| 99久久国产免费福利| 欧洲成人午夜精品无码区久久| 丁香五月综合久久激情| 久久亚洲日韩精品一区二区三区| 久久久久国色AV免费看图片| 久久精品午夜一区二区福利| 狠狠色丁香久久婷婷综合图片| 久久亚洲综合色一区二区三区| 久久人妻AV中文字幕| 久久久精品波多野结衣| 久久精品国产只有精品2020| 久久青青草原精品国产| 久久婷婷五月综合97色直播| 久久精品国产一区二区电影| aaa级精品久久久国产片| 久久精品国产免费观看| 国产精品久久久久久久久软件| 99国内精品久久久久久久| 久久精品国产99久久无毒不卡| 2020国产成人久久精品| 久久一区二区三区99| 久久精品国产99久久丝袜| 亚洲乱亚洲乱淫久久| 久久综合久久综合九色| 国产精品久久久久影院嫩草| avtt天堂网久久精品| 久久精品午夜一区二区福利| 国内精品久久久久伊人av| 少妇久久久久久被弄高潮| 久久天天躁狠狠躁夜夜96流白浆| 久久九九精品99国产精品|