Linear table implementation--array implementation

Source: Internet
Author: User

1#include <stdio.h>2 3 #defineMazsize 204typedefintElemtype;5typedefstruct {6 elemtype data[mazsize];7     intlength;8 }arrlist;9 Ten #defineOK 1 One #defineERROR 0 A #defineTrue 1; - #defineFalse 0; -typedefintStatus; the  -Status initlist (Arrlist *L) - { -L->length =0; +     returnOK; - } +  A Status listempty (arrlist L) at { -     if(L.length = =0) -         return true; -  -     return false; - } in  -Status clearlist (Arrlist *L) to { +L->length =0; -  the     returnOK; * } $ Panax NotoginsengStatus Getelem (Arrlist L,intI, Elemtype *e) - { the     if(I > L.length | | i <1|| l.length==0) +         returnERROR; A*e = l.data[i-1]; the      +     returnOK; - } $  $ Status Locateelem (arrlist L, elemtype e) - { -     if(L.length = =0) the         returnERROR; -     inti;Wuyi      for(i =0; i < l.length; i++) the     { -         if(L.data[i] = =e) Wu              Break; -     } About     if(I >=l.length) $         returnERROR; -     returni +1; - } -  AStatus Listinsert (Arrlist *l,intI, elemtype e) + { the     if(L->length = =mazsize) -         returnERROR; $     if((i<1) || (I> l->length+1)) the         returnERROR; the     intJ; the     if(I <= l->length) the     { -          for(j = l->length; J > I-1; j--) in         { theL-&GT;DATA[J] = l->data[j-1]; the         } About     } thel->data[i-1] =e; thel->length++; the     returnOK; + } -  theStatus Listdelete (Arrlist *l,intI, Elemtype *e)Bayi { the     if(L->length = =0) the         returnERROR; -     if((i<1) && (i>l->length)) -         returnERROR; the     intJ; the*e = L->data[i-1]; the     if(I < l->length) the     { -          for(j = i-1; J < l->length; J + +) the         { theL-&GT;DATA[J] = l->data[j +1]; the         }94     } thel->length--; the     returnOK; the }98  About intListlength (Arrlist *L) - {101     returnL->length;102 }103 104Status createlist (Arrlist *L) the {106     inti;107      for(i =0; i<mazsize; i++)108     {109L->data[i] = i +1; thel->length++;111     } the     returnOK;113 } the voidTraverselist (ConstArrlist *L) the { the     inti;117      for(i =0; I < l->length; i++)118printf"%d", l->data[i]);119printf"\ n");
}

Linear table implementation--array implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.