最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

數(shù)據(jù)結(jié)構(gòu)之?dāng)?shù)組Array實(shí)例詳解

 更新時(shí)間:2017年05月22日 16:40:41   投稿:lqh  
這篇文章主要介紹了數(shù)據(jù)結(jié)構(gòu)之?dāng)?shù)組Array實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下

數(shù)據(jù)結(jié)構(gòu)之?dāng)?shù)組Array實(shí)例詳解

數(shù)組Array

基本操作

Status InitArray(int dimm,...)//若維數(shù)dim和隨后的各維長度合法,則構(gòu)造相應(yīng)的數(shù)組A,并返回OK 
Status DestroyArray()  //銷毀數(shù)組A 
Status Locate(va_list ap,int &off) //若ap指示的各下標(biāo)值合法,則求出該元素在A中相對地址off 
Status Value(ElemType &e,...)  //A是n維數(shù)組,e為元素變量,隨后是n個(gè)下標(biāo)值。若各下表不越界,則e賦值為所指定的A的元素值,并返回OK。 
Status Assign(ElemType e,...)  //A是n維數(shù)組,e為元素變量,隨后是n各下表值。/若各下標(biāo)不越界,則將e的值付給所指定的A的元素,并返回OK。 

幾個(gè)小程序(代碼正誤檢驗(yàn))

// 
//by coolxxx 
//#include<bits/stdc++.h> 
#include<iostream> 
#include<algorithm> 
#include<string> 
#include<iomanip> 
#include<map> 
#include<stack> 
#include<queue> 
#include<set> 
#include<bitset> 
#include<memory.h> 
#include<time.h> 
#include<stdio.h> 
#include<stdlib.h> 
#include<string.h> 
//#include<stdbool.h> 
#include<math.h> 
#define min(a,b) ((a)<(b)?(a):(b)) 
#define max(a,b) ((a)>(b)?(a):(b)) 
#define abs(a) ((a)>0?(a):(-(a))) 
#define lowbit(a) (a&(-a)) 
#define sqr(a) ((a)*(a)) 
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b)) 
#define mem(a,b) memset(a,b,sizeof(a)) 
#define eps (1e-10) 
#define J 10000 
#define mod 1000000007 
#define MAX 0x7f7f7f7f 
#define PI 3.14159265358979323 
#pragma comment(linker,"/STACK:1024000000,1024000000") 
#define N 8 
const int OK=1; 
const int ERROR=0; 
const int INFEASIBLE=-1; 
typedef int Status; 
using namespace std; 
typedef long long LL; 
double anss; 
LL aans; 
int cas,cass; 
LL n,m,lll,ans; 
 
typedef int ElemType; 
#include<stdarg.h>      //標(biāo)準(zhǔn)頭文件,提供宏va_start、va_arg、va_end 用于存取變長參數(shù)表 
const int MAX_ARRAY_DIM=8; //假設(shè)數(shù)組維數(shù)的最大值為8 
typedef struct 
{ 
  ElemType *base;     //數(shù)組元素基址,由InitArray分配 
  int dim;        //數(shù)組維數(shù) 
  int *bounds;      //數(shù)組維界基址,由InitArray分配 
  int *constants;     //數(shù)組映像函數(shù)常量基址,由InitArray分配 
  int elemtotal; 
  Status InitArray(int dimm,...)//若維數(shù)dim和隨后的各維長度合法,則構(gòu)造相應(yīng)的數(shù)組A,并返回OK 
  { 
    int i; 
    va_list ap; 
    if(dimm<1 || dimm>MAX_ARRAY_DIM)return ERROR; 
    dim=dimm; 
    bounds=(int *)malloc(dim*sizeof(int)); 
    if(!bounds)exit(OVERFLOW);//若各維長度合法,則存入A.bounds,并求出A的元素總數(shù)elemtotal 
    elemtotal=1; 
    va_start(ap,dim);  //ap為va_list類型,是存放變長參量數(shù)表信息的數(shù)組 
    for(i=0;i<dim;i++) 
    { 
      bounds[i]=va_arg(ap,int); 
      if(bounds[i]<0)return UNDERFLOW; 
      elemtotal*=bounds[i]; 
    } 
    va_end(ap); 
    base=(ElemType *)malloc(elemtotal*sizeof(ElemType)); 
    if(!base)exit(OVERFLOW); 
    constants=(int *)malloc(dim*sizeof(int)); 
    //求映像函數(shù)的常數(shù)ci,并存入A.constants[i-1],i=1,...,dim 
    if(!constants)exit(OVERFLOW); 
    constants[dim-1]=1; //L=1,指針的增減以元素的大小為單位 
    for(i=dim-2;i>=0;i--) 
      constants[i]=bounds[i+1]*constants[i+1]; 
    return OK; 
  }//InitArray 
   
  Status DestroyArray()  //銷毀數(shù)組A 
  { 
    if(!base)return ERROR; 
    free(base);base=NULL; 
    if(!bounds)return ERROR; 
    free(bounds);bounds=NULL; 
    if(!constants)return ERROR; 
    free(constants);constants=NULL; 
    return OK; 
  }//DestroyArray 
   
  Status Locate(va_list ap,int &off) //若ap指示的各下標(biāo)值合法,則求出該元素在A中相對地址off 
  { 
    int i,ind; 
    off=0; 
    for(i=0;i<dim;i++) 
    { 
      ind=va_arg(ap,int); 
      if(ind<0 || ind>=bounds[i])return OVERFLOW; 
      off+=constants[i]*ind; 
    } 
    return OK; 
  }//Locate 
   
  Status Value(ElemType &e,...)  //A是n維數(shù)組,e為元素變量,隨后是n個(gè)下標(biāo)值。 
                  //若各下表不越界,則e賦值為所指定的A的元素值,并返回OK。 
  { 
    va_list ap; 
    int result,off; 
    va_start(ap,e); 
    if((result=Locate(ap,off))<=0)return result; 
    e=*(base+off); 
    return OK; 
  }//Value 
   
  Status Assign(ElemType e,...)  //A是n維數(shù)組,e為元素變量,隨后是n各下表值。 
                  //若各下標(biāo)不越界,則將e的值付給所指定的A的元素,并返回OK。 
  { 
    va_list ap; 
    int result,off; 
    va_start(ap,e); 
    if((result=Locate(ap,off))<=0)return result; 
    *(base+off)=e; 
    return OK; 
  }//Assign 
   
}Array; 
void ArrayCheck()//代碼正誤檢驗(yàn) 
{ 
  int i,j,k; 
  Array A; 
  ElemType e; 
  A.InitArray(3,2,3,2); 
  printf("維度:%d\n總元素個(gè)數(shù):%d\n各維維界:",A.dim,A.elemtotal); 
  for(i=0;i<A.dim;i++) 
    printf("%d ",A.bounds[i]); 
  puts(""); 
  for(i=0;i<A.bounds[0];i++) 
    for(j=0;j<A.bounds[1];j++) 
      for(k=0;k<A.bounds[2];k++) 
        A.Assign(i*100+j*10+k+111,i,j,k); 
  for(i=0;i<A.bounds[0];i++,puts("")) 
    for(j=0;j<A.bounds[1];j++,puts("")) 
      for(k=0;k<A.bounds[2];k++) 
        printf("%d ",(A.Value(e,i,j,k),e)); 
  A.DestroyArray(); 
  puts(""); 
} 
程序結(jié)果: 
維度:3 
總元素個(gè)數(shù):12 
各維維界:2 3 2 
111 112 
121 122 
131 132 
 
211 212 
221 222 
231 232 

主函數(shù):

int main() 
{ 
  #ifndef ONLINE_JUDGEW 
// freopen("1.txt","r",stdin); 
  freopen("2.txt","w",stdout); 
  #endif 
  int i,j,k; 
  int x,y,z,xx,yy; 
// init(); 
// for(scanf("%d",&cass);cass;cass--) 
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++) 
// while(~scanf("%s",s)) 
// while(~scanf("%d%d",&n,&m)) 
  { 
    ArrayCheck(); 
  } 
  return 0; 
} 

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

  • C++多線程之帶返回值的線程處理函數(shù)解讀

    C++多線程之帶返回值的線程處理函數(shù)解讀

    這篇文章主要介紹了C++多線程之帶返回值的線程處理函數(shù)解讀,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • C/C++實(shí)現(xiàn)圖書信息管理系統(tǒng)

    C/C++實(shí)現(xiàn)圖書信息管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了c/c++實(shí)現(xiàn)圖書信息管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • C語言實(shí)現(xiàn)掃雷游戲詳解

    C語言實(shí)現(xiàn)掃雷游戲詳解

    這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)掃雷游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-01-01
  • C語言中結(jié)構(gòu)體、聯(lián)合體的成員內(nèi)存對齊情況

    C語言中結(jié)構(gòu)體、聯(lián)合體的成員內(nèi)存對齊情況

    這篇文章主要給大家介紹了關(guān)于C語言中結(jié)構(gòu)體、聯(lián)合體的成員內(nèi)存對齊情況的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • C++基于prim實(shí)現(xiàn)迷宮生成

    C++基于prim實(shí)現(xiàn)迷宮生成

    這篇文章主要為大家詳細(xì)介紹了C++基于prim實(shí)現(xiàn)迷宮生成,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • 詳解C++?中?shared_ptr?weak_ptr

    詳解C++?中?shared_ptr?weak_ptr

    shared_ptr?是一個(gè)標(biāo)準(zhǔn)的共享所有權(quán)的智能指針,允許多個(gè)指針指向同一個(gè)對象,定義在?memory?文件中,命名空間為?std,這篇文章主要介紹了C++?中?shared_ptr?weak_ptr,需要的朋友可以參考下
    2022-07-07
  • C++?Boost?Assign超詳細(xì)講解

    C++?Boost?Assign超詳細(xì)講解

    Boost是為C++語言標(biāo)準(zhǔn)庫提供擴(kuò)展的一些C++程序庫的總稱。Boost庫是一個(gè)可移植、提供源代碼的C++庫,作為標(biāo)準(zhǔn)庫的后備,是C++標(biāo)準(zhǔn)化進(jìn)程的開發(fā)引擎之一,是為C++語言標(biāo)準(zhǔn)庫提供擴(kuò)展的一些C++程序庫的總稱
    2022-12-12
  • Matlab繪制酷炫坐標(biāo)區(qū)域的方法詳解

    Matlab繪制酷炫坐標(biāo)區(qū)域的方法詳解

    這篇文章主要為大家詳細(xì)介紹了如何利用Matlab編寫一個(gè)能讓坐標(biāo)區(qū)域變得很炫酷的修飾函數(shù),文中的示例代碼講解詳細(xì),感興趣的可以了解一下
    2022-05-05
  • C++程序中使用Windows系統(tǒng)Native Wifi API的基本教程

    C++程序中使用Windows系統(tǒng)Native Wifi API的基本教程

    這篇文章主要介紹了C++程序中使用Windows系統(tǒng)Native Wifi API的基本教程,包括在程序中控制無線網(wǎng)卡開關(guān)的方法,需要的朋友可以參考下
    2016-03-03
  • 詳解C語言之動態(tài)內(nèi)存管理

    詳解C語言之動態(tài)內(nèi)存管理

    本文主要介紹了C語言動態(tài)內(nèi)存管理的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11

最新評論

莱州市| 阳山县| 衡水市| 永安市| 铜陵市| 哈密市| 营山县| 长治市| 姚安县| 特克斯县| 宜兴市| 大石桥市| 灵寿县| 永吉县| 共和县| 青阳县| 乌拉特前旗| 夹江县| 霸州市| 雅安市| 旺苍县| 金门县| 屏南县| 衡阳县| 沽源县| 沅陵县| 宜兴市| 墨竹工卡县| 桂阳县| 崇礼县| 礼泉县| 安图县| 临颍县| 自治县| 邵武市| 柯坪县| 锡林浩特市| 尤溪县| 溆浦县| 灵武市| 阿瓦提县|