读书人

单链表安插

发布时间: 2013-01-18 10:22:42 作者: rapoo

单链表插入
class A {

struct B {
C *m_function;
struct B *m_next;
};

static struct B *head;

public:
static void insert(C *f);
};

A::B *A::head;

void A::insert(C *f)
{
struct B *old=head;
head = new struct B;
head->C = f;
head->m_next = old;

}

C::C()
{

A::insert(this);
}

有段错误
[解决办法]
不知道你想要什么,你的代码也不全,我自己加了一下。自己看吧,只是编译可过,
是不是你想要的不知道。


class C;
class A
{
struct B
{
C *m_function;
struct B *m_next;
};
static struct B *head;
public:
static void insert(C *f);
};

class C
{
public:
C()
{
A::insert(this);
}
};

A::B *A::head;

void A::insert(C *f)
{
struct B *old=head;
head = new struct B;
head->m_function = f;
head->m_next = old;
}

读书人网 >C语言

热点推荐