zoukankan      html  css  js  c++  java
  • seqlist template

     1 #include <iostream.h>
     2 typedef int ElemType;
     3 typedef struct{
     4    ElemType *elem;
     5    int length;
     6 }SeqList;
     7 
     8 void InitSeq(SeqList &L,int n,ElemType a[])
     9 {  int i=0;
    10    L.elem=new ElemType[n];
    11    while(i<n)
    12    {L.elem[i]=a[i];i++;}
    13    L.length=n;
    14 }
    15 void DispSeq(SeqList L)
    16 {
    17     int i=0;
    18        while(i<L.length)
    19    {cout<<L.elem[i]<<'\t';i++;}
    20 }
    21 void UnionSeq(SeqList L1,SeqList L2,SeqList &L3)
    22 {
    23    L3.length=L1.length+L2.length;
    24    L3.elem=new ElemType[L3.length];
    25    ElemType* pa,*pb,*pc;
    26    pa=&L1.elem[0];
    27    pb=&L2.elem[0];
    28    pc=&L3.elem[0];
    29    while(pa<L1.elem+L1.length&&pb<L2.elem+L2.length)
    30    {
    31        if(*pa<*pb)
    32        {*pc=*pa;pa++;pc++;}
    33        else
    34        {*pc=*pb;pb++;pc++;}
    35    }
    36    while(pb<L2.elem+L2.length)
    37    {*pc=*pb;pb++;pc++;}
    38     while(pa<L1.elem+L1.length)
    39    {*pc=*pa;pa++;pc++;}
    40 }
    41 
    42 
    43 
    44 void main()
    45 {
    46    SeqList L1,L2,L3;
    47    ElemType a[100]={2,6,8};
    48    ElemType b[100]={1,3,5,7};
    49    InitSeq(L1,3,a);
    50    InitSeq(L2,4,b);
    51    DispSeq(L1);cout<<endl;
    52    DispSeq(L2);
    53    UnionSeq(L1,L2,L3);
    54    cout<<endl;
    55    DispSeq(L3);
    56 }
  • 相关阅读:
    Javascript 基础知识整理
    设计模式
    Flex 布局
    CSS选择器,属性前缀,长度单位,变形效果,过渡效果,动画效果
    CSS中一些重要概念
    性能优化(CSS优化)
    CSS定位走一波(定位学习续)
    定位布局
    浮动布局
    Display属性学习总结
  • 原文地址:https://www.cnblogs.com/ewitt/p/6496979.html
Copyright © 2011-2022 走看看