• 初学数据结构三


     1 L = (LinkList) malloc(sizeof(LNode));
     2 P = L;
     3 for (i = 1; i <= 4; i++)
     4 {
     5    P->next = (LinkList) malloc(sizeof(LNode));
     6    P = P->next;
     7    P->data = i * 2 - 1;
     8 }
     9 P->next = NULL;
    10 for (i = 4; i >= 1; i--)
    11     Ins_LinkList(L, i + 1,i * 2);
    12 for (i = 1; i <= 3; i++)
    13     Del_LinkList(L, i);
    14 
    15 Status DeleteK(SqList &a, int i, int k)
    16 {
    17     int j;
    18     if (i<0 || i>a.length - 1 || k<0 || k>a.length - i)
    19         return INFEASIBLE;
    20     for (j = 0; j <= k; j++)
    21         a.elem[j + i] = a.elem[j + i + k];
    22     a.length = a.length - k;
    23     return OK;
    24 }
    25 
    26 Status InsertOrderList(SqList &va, ElemType x)
    27 {
    28     int i;
    29     if (va.length == va.listsize)
    30         return(OVERFLOW);
    31     for (i = va.length; i > 0&&x < va.elem[i - 1]; i--)
    32         va.elem[i] = va.elem[i - 1];
    33     va.elem[i] = x;
    34     va.length++;
    35     return OK;
    36 }
    37 
    38 Status CompareOrderList(SqList &A, SqKist &B)
    39 {
    40     int
    41 }
      1 L = (LinkList) malloc(sizeof(LNode));
      2 P = L;
      3 for (i = 1; i <= 4; i++)
      4 {
      5    P->next = (LinkList) malloc(sizeof(LNode));
      6    P = P->next;
      7    P->data = i * 2 - 1;
      8 }
      9 P->next = NULL;
     10 for (i = 4; i >= 1; i--)
     11     Ins_LinkList(L, i + 1,i * 2);
     12 for (i = 1; i <= 3; i++)
     13     Del_LinkList(L, i);
     14 
     15 Status DeleteK(SqList &a, int i, int k)
     16 {
     17     int j;
     18     if (i<0 || i>a.length - 1 || k<0 || k>a.length - i)
     19         return INFEASIBLE;
     20     for (j = 0; j <= k; j++)
     21         a.elem[j + i] = a.elem[j + i + k];
     22     a.length = a.length - k;
     23     return OK;
     24 }
     25 
     26 Status InsertOrderList(SqList &va, ElemType x)
     27 {
     28     int i;
     29     if (va.length == va.listsize)
     30         return(OVERFLOW);
     31     for (i = va.length; i > 0&&x < va.elem[i - 1]; i--)
     32         va.elem[i] = va.elem[i - 1];
     33     va.elem[i] = x;
     34     va.length++;
     35     return OK;
     36 }
     37 
     38 Status CompareOrderList(SqList &A, SqList &B)
     39 {
     40     int i, k,j;
     41     k = A.length > B.length ? A.length : B.length;
     42     for (i = 0; i < k; i++)
     43     {
     44         if (A.elem[i] > B.elem[i])
     45             j = 1;
     46         if (A.elem[i] < B.elem[i])
     47             j = -1;
     48     }
     49     if (A.length > k)
     50         j = 1;
     51     if (B.length > k)
     52         j = -1;
     53     if (A.length == B.length)
     54         j = 0;
     55     return j;
     56 }
     57 
     58 int LocateElem_L(LinkList&L, ElemType x)
     59 {
     60     int i = 0;
     61     LinkList p = L;
     62     while (p && p->data != x){
     63       p = p->next;
     64        i++;
     65     }
     66     if (!p)
     67         return 0;
     68     else
     69         return i;
     70 }
     71 
     72 int ListLength_L(LinkList &L)
     73 {
     74     int i = 0;
     75     LinkList p = L;
     76     if (p)
     77         p = p->next;
     78     while (p)
     79     {
     80         p = p->next;
     81         i++;
     82     }
     83     return i;
     84 }
     85 
     86 void MergeList_L(LinkList &ha, LinkList&hb, LinkList&hc)
     87 {
     88     LinkList pa, pb;
     89     pa = ha;
     90     pb = hb;
     91     while (pa->next && pb->next)
     92     {
     93         pa = pa->next;
     94         pb = pb->next;
     95     }
     96     if (!pa->next)
     97     {
     98         hc = hb;
     99         while (pb->next)
    100             pb = pb->next;
    101         pb->next = ha->next;
    102     }
    103     else
    104     {
    105         hc = ha;
    106         while (pa->next)
    107             pa = pa->next;
    108         pa->next = hb->next;
    109     }
    110 }
     1 Status DeleteAndInsertSub(LinkedList la, LinkedList lb, int i, int j, int len)
     2 {
     3     if (i < 0 || j < 0 || len < 0)
     4         return INFEASIBLE;
     5     p = la;
     6     k = 1;
     7     while (k < i)
     8     {
     9         p = p->next; 
    10         k++;
    11     }
    12     q = p;
    13     while (k <= len)
    14     {
    15         q = q->next;
    16         k++;
    17     }
    18     s = lb;
    19     k = 1;
    20     while (k < j)
    21     {
    22         s = s->next;
    23         k++;
    24     }
    25     s->next = p;
    26     q->next = s->next;
    27     return OK;
    28 }
    29 
    30 Status DeleteAndInsertSub(LinkList &la, linklist&lb, int i, int j, int len)
    31 {
    32     LinkList p, q, s, prev = NULL;
    33     int k = 1;
    34     if (i < 0 || j < 0 || len < 0)
    35         return INFEASIBLE;
    36     p = la;
    37     while (p && k < i)
    38     {
    39         prev = p;
    40         p = p->next;
    41         k++;
    42     }
    43     if (!p)
    44         return INFEASIBLE;
    45     q = p;
    46     k = 1;
    47     while (q && k < len)
    48     {
    49         q = p->next;
    50         k++;
    51     }
    52     if (!q)
    53         return INFEASIBLE;
    54     if (!prev)
    55         la = q->next;
    56     else
    57         prev->next = q->next;
    58     if (j = 1)
    59     {
    60         q->next = lb;
    61         lb = p;
    62     }
    63     else
    64     {
    65         s = lb;
    66         k = 1;
    67         while (s && k < j - 1)
    68         {
    69             s = s->next;
    70             k++;
    71         }
    72         if (!s)
    73             return INFEASIBLE;
    74         q->next = s->next;
    75         s->next = p;
    76     }
    77     return OK;
    78 }
  • 相关阅读:
    BETA 版冲刺前准备
    Alpha 事后诸葛亮(团队)
    Learn Docker(一)—软件安装与常规操作
    Alpha 答辩总结
    Alpha 冲刺 (10/10)
    Alpha 冲刺 (9/10)
    Alpha 冲刺 (8/10)
    Alpha 冲刺 (7/10)
    Alpha 冲刺 (6/10)
    团队作业-随堂小测(同学录)
  • 原文地址:https://www.cnblogs.com/Zblogs/p/3346704.html
Copyright © 2020-2023  润新知