首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

生手 求解到底哪错了(create处报错)

2013-10-11 
新手 求解到底哪错了(create处报错)#include iostreamusing namespace stdtypedef struct node{char da

新手 求解到底哪错了(create处报错)

#include <iostream>
using namespace std;

typedef struct node
{
    char data;
    node * next;
}NODE,*PNODE;

PNODE create();
void showList(PNODE pHead);

int main()
{

    PNODE head;
    head = create();
    showList(head);
    
    return 0;
}

PNODE create()
{
    PNODE head=NULL;
    PNODE pEnd = head;
    PNODE ps;
    char temp;
    cout<<"Please input a string end with '#' :"<<endl;
    do {
        cin>>temp;
        if(temp != '#')
        {
            ps=new node;
            ps->data=temp;
            ps->next=NULL;
            
            if(head == NULL)
            {
                head = ps;
            }
            else
            {
                pEnd->next = ps;
            }
            pEnd=ps;
        }
    } while (temp != '#');
    return  head;
}

void showList(PNODE head)
{
    PNODE pRead = head;
    cout<<"The data of the link list are: "<<endl;
    while(pRead != NULL)
    {
        cout<<pRead->data;
        pRead=pRead->next;
    }
    cout<<endl;
}
Thread?1?? breakpoint?
[解决办法]
create处出现什么错误?

引用:
#include <iostream>
using namespace std;

typedef struct node
{
    char data;
    node * next;
}NODE,*PNODE;

PNODE create();
void showList(PNODE pHead);

int main()
{

    PNODE head;
    head = create();
    showList(head);
    
    return 0;
}

PNODE create()
{
    PNODE head=NULL;
    PNODE pEnd = head;
    PNODE ps;
    char temp;
    cout<<"Please input a string end with '#' :"<<endl;
    do {
        cin>>temp;
        if(temp != '#')
        {
            ps=new node;
            ps->data=temp;
            ps->next=NULL;
            
            if(head == NULL)
            {
                head = ps;
            }
            else
            {


                pEnd->next = ps;
            }
            pEnd=ps;
        }
    } while (temp != '#');
    return  head;
}

void showList(PNODE head)
{
    PNODE pRead = head;
    cout<<"The data of the link list are: "<<endl;
    while(pRead != NULL)
    {
        cout<<pRead->data;
        pRead=pRead->next;
    }
    cout<<endl;
}


[解决办法]

VS没问题!
[解决办法]
表示看不出来有什么问题!楼主确认下输入再试试!

热点排行