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

单链表安插

2013-01-18 
单链表插入class A {struct B {C *m_functionstruct B *m_next}static struct B *head public:static

单链表插入
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;
}

热点排行