结构体

#include<iostream>
using namespace std;
struct Node
{ char data;
  Node *next;
 };

int main()
{
   Node *head=NULL,*q,*p;
   int n=0;
   p=new Node;
   cout<<"Input a char:";
   cin>>p->data;
   while(p->data!='*')
   {
     n++;
     if(n==1) head=p;
     else q->next=p;
     q=p;
     p=new Node;
     cout<<"Input a char:";
     cin>>p->data;
   };
   q->next=NULL;
   cout<<"Points="<<n<<endl;
   p=head;
   while(p!=NULL)
   { cout<<p->data<<"  ";
     q=p;
     p=p->next;
     delete q;
   }
   cout<<endl;

}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务