注册 登录
编程论坛 数据结构与算法

创建一个单链表,错在哪里

qweiuy566 发布于 2016-04-03 19:14, 4408 次点击
#include<iostream>
using namespace std;
class list
{
public:
    int newlist;
private:
    char *elem;
    int length;
    int listsize;

}
list::newlist()
{
    printf("创建一个单链表");
    elem=(ElemType *)malloc(sizeof(ElemType)) ;
    if(elem==NULL)
    return(ERROR);
    lenght=0;
    return OK;
}
main()
{
    newlist;
}
5 回复
#2
我不会喜欢你2016-04-09 22:17
程序代码:
#include<iostream>
using namespace std;
class list
{
public:
    int newlist;
private:
    char *elem;
    int length;
    int listsize;

}
list::newlist()
{
    printf("创建一个单链表");
    elem=(ElemType *)malloc(sizeof(ElemType)) ;   //这个应该有问题吧
    if(elem==NULL)
    return(ERROR);
    lenght=0;
    return OK;
}
main()
{
    newlist;
}

请问一下这是c++吗?我没有学过,
#3
T11651702412016-04-10 18:24
回复 2楼 我不会喜欢你
这就是c++,我也没有学过
#4
zhulei19782016-04-17 12:04
elem=(ElemType *)malloc(sizeof(ElemType)) ;          这是c的语法
#5
zhulei19782016-04-17 12:05
main()
{
    newlist();
}
#6
lanke7112016-05-08 22:29
malloc是C语言的,
C++的话,应该用new来分配空间
而不是用malloc来分配空间
1