码迷,mamicode.com
首页 > 其他好文 > 详细

关于链表创建

时间:2019-06-18 14:06:48      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:节点   new   方式   空间   lis   函数   类型   单链表   tor   

22 void newList(node & head,int length){
23     node *a=new node[length];//这是这个函数的解释node* operator [] (int n)P11行 申请空间的方式 new int[10]申请10个int类型的空间 再返回node指针类型
24     for(int i=0;i<length;++i)cin>>a[i].data>>a[i].index;
25          //a是node类型数组啊
26     sort(a,a+length);//p16行的函数解释
27     node* end=&head;
28     for(int i=0;i<length;++i){
29         node* t=new node;
30         t->data=a[i].data;
31         t->index=a[i].index;
32         end->next=t;
33         end=t;
34     }//他这好像就特别简单 end=xx  之后就申请了新节点 赋值 然后挂上去
35     delete[] a;
36 }

 

 

void Create(Node *head)
{ //头插法,创建单链表
 int x;
 while(cin>>x)
 {
     if(x==0)break;
     Node *t=new Node;
     t->data=x;t->next=head->next;
     head->next=t;
 }

}

 

我有点慌。。。。

关于链表创建

标签:节点   new   方式   空间   lis   函数   类型   单链表   tor   

原文地址:https://www.cnblogs.com/yundong333/p/11044553.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!