#include<iostream.h>
struct node
{ char data;
struct node *next;
};
typedef struct node *link;
class Tdlb
{
private:
link head;
public:
Tdlb(char a[],int n);
void inver();
void print();
};
Tdlb::Tdlb(char a[],int n)
{
link p;
int i;
head=new node; head->next=NULL;
for (i=n-1;i>=0;i--)
{
p=new node;p->data=a[i];
p->next=head->next;head->next =p;
}
};
void Tdlb::inver()
{
link p,s;
p=head->next;head->next=NULL;
while (p!=NULL)
{
s=p;p=p->next;
s->next=head->next;head->next=s;
}
}
void Tdlb::print()
{
for(head=head->next;head!=NULL;head=head->next)
cout<< head->data;
cout<<endl;
}
void main()
{
char arr[]={"abcdefg"};
int N=8;
Tdlb ex(arr,N);
ex.print();
ex.inver();
ex.print();
}
编译后老是提示遇到问题须要关闭,郁闷.
我是用visual c++6.0编译的。