- void newList(node & head,int length){
- node *a=new node[length];// 这是这个函数的解释 node* operator [] (int n)P11 行 申请空间的方式 new int[10] 申请 10 个 int 类型的空间 再返回 node 指针类型
- for(int i=0;i<length;++i)cin>>a[i].data>>a[i].index;
- //a 是 node 类型数组啊
- sort(a,a+length);//p16 行的函数解释
- node* end=&head;
- for(int i=0;i<length;++i){
- node* t=new node;
- t->data=a[i].data;
- t->index=a[i].index;
- end->next=t;
- end=t;
- }// 他这好像就特别简单 end=xx 之后就申请了新节点 赋值 然后挂上去
- delete[] a;
- }
- 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;
- }
- }
我有点慌....
来源: http://www.bubuko.com/infodetail-3096196.html