小错误变成大错误 不知道该怎么改了 应该是指针悬挂问题吧

不能正常退出,以确定是析构函数的问题,而且是当前指针current的事,先放着做遗留问题吧,真没时间耗了,先往下做,会变好的 ,  那位要是看到了 ,希望给指点,帮改之,谢了!

///"ListNode"/
#ifndef NULL
#define NULL 0
#endif

class List;
class ListNode{
friend class List;
private:
char element;
ListNode* Next;
public:
ListNode(const char& e,ListNode* N=NULL):element(e),Next(N){}
ListNode():Next(NULL){}
~ListNode(){}
};

/"List"/

#include"ListNode.h"

#include"h.h"


class Bracket;
class List{
friend class Bracket;
private:
ListNode* head;
ListNode* current;
public:
List(){head=new ListNode();current=head;}

~List(){MakeEmpty();delete head;delete current; }
int Is_Empty()const{return head->Next==NULL;}
void MakeEmpty(){while(!Is_Empty()) PopFirst();}
void EnList(const char& e)
{
  ListNode* p=new ListNode(e,current->Next);
  current=current->Next=p;
}
const char& ShowFirst(){ return head->Next->element;}
void PopFirst()
{
  ListNode* p=head->Next;
  head->Next=p->Next;
  delete p;
}
};

/"Stack"


#include"h.h"

class Bracket;
static const int InitSize=10;
class Stack{
friend class Bracket;
private:
char* Array;
int top;
int MaxSize;
void DoubleSize(int Max);
public:
Stack():top(-1),MaxSize(InitSize){Array=new char[MaxSize];}
~Stack(){delete []Array;}
int Is_StackEmpty()const{return top==-1;}
int Is_StackFull()const{return top==MaxSize-1;}
void EnStack(const char& e);
void PopStack();
const char& ShowTop(){ return Array[top];}
};

void Stack::EnStack(const char& e)
{
if(++top==MaxSize) DoubleSize(2*MaxSize);
Array[top]=e;
}

void Stack::DoubleSize(int Max)
{
char* oldArray=Array;
Array=new char[Max];
int j;
for(j=0;j<=top;j++) Array[j]=oldArray[j];
MaxSize=Max;
delete[]oldArray;
}

void Stack::PopStack()
{
top--;
}

/"Bracket"/

#include"Stack.h"
#include"List.h"
#include"h.h"

class Bracket{
private:
List L;
Stack S;
public:
Bracket(const List& Li,const Stack& St):L(Li),S(St){}
~Bracket(){}
friend istream& operator>>(istream& is,Bracket& b);
friend ostream& operator<<(ostream& os,Bracket& b);
};


istream& operator>>(istream& is,Bracket& b)
{
cout<<"Please input words:"<<endl;
char c;
while(cin.get(c)&&c!='#')
{
  if(c=='('||c=='{'||c=='['){ b.S.EnStack(c);   b.L.EnList(c);}
  else if(c==')'||c=='}'||c==']')
  {
   if(b.S.Is_StackEmpty())cout<<"ERROR!!!The first one can not be RIGHT!!"<<endl;
   else if(c==')'&&b.S.ShowTop()=='('){b.S.PopStack();b.L.EnList(c);}
   else if(c=='}'&&b.S.ShowTop()=='{'){b.S.PopStack();b.L.EnList(c);}
   else if(c==']'&&b.S.ShowTop()=='['){b.S.PopStack();b.L.EnList(c);}
   else cout<<"ERROR! Mach to NOONE!!"<<endl;
  }
  else b.L.EnList(c);
}//end while
return is;
}


ostream& operator<<(ostream& os,Bracket& b)
{
cout<<"Output the word:"<<endl;
char c;
while(!b.L.Is_Empty())
{
  c=b.L.ShowFirst();
  b.L.PopFirst();
  cout.put(c);
}
cout<<endl;
return os;
}

"h"///

#ifndef _H_H
#define _H_H
#endif


#include<iostream>
using namespace std;

//"main"/

#include"Bracket.h"

int main()
{

List L;
Stack S;
Bracket B(L,S);
cin>>B;
cout<<"--------->"<<endl;
cout<<B;
cout<<endl;

return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值