首页 > 其他 > 详细

关于链表创建

时间:2019-06-18 13:48:13      阅读:110      评论:0      收藏:0      [点我收藏+]
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;
 }

}

 

我有点慌。。。。

关于链表创建

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!