求大神指点一二!小弟感激不尽
#include <iostream>
#include <string>
#include <malloc.h>
using namespace std;
typedef struct node
{
node *prior;
node *next;
string data;
}*s;
node *receive(node *p,int &i)
{
node *q;
node *head;
head=(node *)malloc(sizeof(node));
q=head;
char ch;
do
{
p=(node *)malloc(sizeof(node));
cin>>p->data;//为什么在接收数据时停止了?
//求大神详解
p->prior=q;
p->next=q->next;
q->next=p;
q=p;
i++;
ch=cin.get();
}while(ch!='\n');
p->next=head->next;
head->next->prior=p;
free(head);
return p->next;
}
int main()
{
node *p,*s;
int sum;
p=receive(s,sum);
int j;
for(j=0;j<sum;j++)
{
cout<<p->data<<' ';
p=p->prior;
}
return 0;
}
调试接收数据时竟然停止了!求大神详解