zoukankan      html  css  js  c++  java
  • 链表之创建

     1 /*
     2 头尾插创建链表。
     3 
     4 */
     5 
     6 
     7 #include <stdio.h>
     8 #include <stdlib.h>
     9 #include "sys/malloc.h"
    10 
    11 void CreateList(LinkList *L,int n){
    12     int i;
    13     LinkList p;
    14     *L=(LinkList)malloc(sizeof(struct LNode));
    15     (*L)->next=NULL;
    16     printf("Please input  Link_len = %d : \n",n);
    17     for(i=n;i>0;--i){
    18         p=(LinkList)malloc(sizeof(struct LNode));
    19         scanf("%d",&p->data);
    20         p->next=(*L)->next;
    21         (*L)->next=p;
    22     }
    23 }
    24 
    25 void CreatList1(LinkList *L,int n){
    26     int i;
    27     LinkList p,q;
    28     (*L)=(LinkList)malloc(sizeof(struct LNode));
    29     (*L)->next=NULL;
    30     q=(*L);
    31     printf("Please input  Link_len = %d : \n",n);
    32     for(i=n;i>0;--i){
    33         p=(LinkList)malloc(sizeof(struct LNode));
    34         scanf("%d",&p->data);
    35         q->next=p;
    36         q=q->next;
    37     }
    38     p->next=NULL;
    39 }
    40 
    41 void MergeList(LinkList La,LinkList Lb,LinkList *Lc){
    42     LinkList pa=La->next;pb=Lb->next;pc;
    43     Lc=pc=La;
    44     while(pa&&pb){
    45         if(pa->data<=pb->data){
    46             pc->next=pa;
    47             pc=pa;
    48             pa=pa->next;
    49         }
    50         else{
    51             pc->next=pb;
    52             pc=pb;
    53             pb=pb->next;
    54         }
    55         pc->next=pa?pa:pb;
    56         free(Lb);
    57         Lb=NULL;
    58     }
    59 }
  • 相关阅读:
    Android
    Android
    Android
    JAVA动态代理基础
    TCP连接与OKHTTP复用连接池
    Android
    Android
    GitHub上README.md教程
    android
    HDU 1097 A hard puzzle
  • 原文地址:https://www.cnblogs.com/suiyun/p/2875302.html
Copyright © 2011-2022 走看看