C++之数据结构,单链表

用结构体构建单链表例子:

int main ()
{
  struct student head;
  struct student body;
  struct student end;
  struct student *p;

  head.a = 10;
  head.b = 20;

  body.a = 30;
  body.b = 40;

  end.a = 50;
  end.b = 60;

  head.next = &body;
  body.next = &end;
  end.next = NULL;

  p = &head;
  do{
    cout<<p->a<<p->b<<"\n";
    p = p->next;
  }while(p != NULL);

}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。