使用C语言实现vector动态数组的实例分享

 更新时间:2016年05月11日 14:49:33   作者:旭子  
vector是指能够存放任意类型的动态数组,而C语言中并没有面向对象的C++那样内置vector类,所以我们接下来就来看一下使用C语言实现vector动态数组的实例,需要的朋友可以参考下

下面是做项目时实现的一个动态数组,先后加入了好几个之后的项目,下面晒下代码。

头文件:

# ifndef __CVECTOR_H__ 
# define __CVECTOR_H__ 
# define MIN_LEN 256 
# define CVEFAILED -1 
# define CVESUCCESS 0 
# define CVEPUSHBACK 1 
# define CVEPOPBACK 2 
# define CVEINSERT  3 
# define CVERM    4 
# define EXPANED_VAL 1 
# define REDUSED_VAL 2 
 
typedef void *citerator; 
typedef struct _cvector *cvector; 
 
# ifdef _cplusplus 
# define EXTERN_ extern "C" 
# else 
# define EXTERN_ extern 
# endif 
 
EXTERN_ cvector  cvector_create  (const size_t size              ); 
EXTERN_ void   cvector_destroy (const cvector cv              ); 
EXTERN_ size_t  cvector_length  (const cvector cv              ); 
EXTERN_ int    cvector_pushback (const cvector cv, void *memb        ); 
EXTERN_ int    cvector_popback (const cvector cv, void *memb        ); 
EXTERN_ size_t  cvector_iter_at (const cvector cv, citerator iter      ); 
EXTERN_ int    cvector_iter_val (const cvector cv, citerator iter, void *memb); 
EXTERN_ citerator cvector_begin  (const cvector cv              ); 
EXTERN_ citerator cvector_end   (const cvector cv              ); 
EXTERN_ citerator cvector_next   (const cvector cv, citerator iter      ); 
EXTERN_ int    cvector_val_at  (const cvector cv, size_t index, void *memb ); 
EXTERN_ int    cvector_insert  (const cvector cv, citerator iter, void *memb); 
EXTERN_ int    cvector_insert_at(const cvector cv, size_t index, void *memb ); 
EXTERN_ int    cvector_rm    (const cvector cv, citerator iter      ); 
EXTERN_ int    cvector_rm_at  (const cvector cv, size_t index       );  
 
/* for test */ 
EXTERN_ void   cv_info     (const cvector cv              ); 
EXTERN_ void   cv_print     (const cvector cv              ); 
#endif /* EOF file cvector.h */ 


C文件:

# include <stdio.h> 
# include <stdlib.h> 
# include <string.h> 
# include <unistd.h> 
# define MIN_LEN 256 
# define CVEFAILED -1 
# define CVESUCCESS 0 
# define CVEPUSHBACK 1 
# define CVEPOPBACK 2 
# define CVEINSERT  3 
# define CVERM    4 
# define EXPANED_VAL 1 
# define REDUSED_VAL 2 
 
typedef void *citerator; 
typedef struct _cvector  
{    
  void *cv_pdata; 
  size_t cv_len, cv_tot_len, cv_size; 
} *cvector; 
 
# define CWARNING_ITER(cv, iter, file, func, line) \ 
  do {\ 
    if ((cvector_begin(cv) > iter) || (cvector_end(cv) <= iter)) {\ 
      fprintf(stderr, "var(" #iter ") warng out of range, "\ 
          "at file:%s func:%s line:%d!!/n", file, func, line);\ 
      return CVEFAILED;\ 
    }\ 
  } while (0) 
 
# ifdef _cplusplus 
# define EXTERN_ extern "C" 
# else 
# define EXTERN_ extern 
# endif 
 
EXTERN_ cvector  cvector_create  (const size_t size              ); 
EXTERN_ void   cvector_destroy (const cvector cv              ); 
EXTERN_ size_t  cvector_length  (const cvector cv              ); 
EXTERN_ int    cvector_pushback (const cvector cv, void *memb        ); 
EXTERN_ int    cvector_popback (const cvector cv, void *memb        ); 
EXTERN_ size_t  cvector_iter_at (const cvector cv, citerator iter      ); 
EXTERN_ int    cvector_iter_val (const cvector cv, citerator iter, void *memb); 
EXTERN_ citerator cvector_begin  (const cvector cv              ); 
EXTERN_ citerator cvector_end   (const cvector cv              ); 
EXTERN_ citerator cvector_next   (const cvector cv, citerator iter      ); 
EXTERN_ int    cvector_val_at  (const cvector cv, size_t index, void *memb ); 
EXTERN_ int    cvector_insert  (const cvector cv, citerator iter, void *memb); 
EXTERN_ int    cvector_insert_at(const cvector cv, size_t index, void *memb ); 
EXTERN_ int    cvector_rm    (const cvector cv, citerator iter      ); 
EXTERN_ int    cvector_rm_at  (const cvector cv, size_t index       ); 
 
/* for test */ 
EXTERN_ void   cv_info     (const cvector cv              ); 
EXTERN_ void   cv_print     (const cvector cv              ); 
 
cvector cvector_create(const size_t size) 
{ 
  cvector cv = (cvector)malloc(sizeof (struct _cvector)); 
 
  if (!cv) return NULL; 
 
  cv->cv_pdata = malloc(MIN_LEN * size); 
 
  if (!cv->cv_pdata)  
  { 
    free(cv); 
    return NULL; 
  } 
 
  cv->cv_size = size; 
  cv->cv_tot_len = MIN_LEN; 
  cv->cv_len = 0; 
 
  return cv; 
} 
 
void cvector_destroy(const cvector cv) 
{ 
  free(cv->cv_pdata); 
  free(cv); 
  return; 
} 
 
size_t cvector_length(const cvector cv) 
{ 
  return cv->cv_len; 
} 
 
int cvector_pushback(const cvector cv, void *memb) 
{ 
  if (cv->cv_len >= cv->cv_tot_len)  
  { 
    void *pd_sav = cv->cv_pdata; 
    cv->cv_tot_len <<= EXPANED_VAL; 
    cv->cv_pdata = realloc(cv->cv_pdata, cv->cv_tot_len * cv->cv_size); 
 
    if (!cv->cv_pdata)  
    { 
      cv->cv_pdata = pd_sav; 
      cv->cv_tot_len >>= EXPANED_VAL; 
      return CVEPUSHBACK; 
    } 
  } 
 
  memcpy(cv->cv_pdata + cv->cv_len * cv->cv_size, memb, cv->cv_size); 
  cv->cv_len++; 
 
  return CVESUCCESS; 
} 
 
int cvector_popback(const cvector cv, void *memb) 
{ 
  if (cv->cv_len <= 0) return CVEPOPBACK; 
 
  cv->cv_len--; 
  memcpy(memb, cv->cv_pdata + cv->cv_len * cv->cv_size, cv->cv_size); 
 
  if ((cv->cv_tot_len >= (MIN_LEN << REDUSED_VAL))  
      && (cv->cv_len <= (cv->cv_tot_len >> REDUSED_VAL)))  
  { 
    void *pd_sav = cv->cv_pdata; 
    cv->cv_tot_len >>= EXPANED_VAL; 
    cv->cv_pdata = realloc(cv->cv_pdata, cv->cv_tot_len * cv->cv_size); 
 
    if (!cv->cv_pdata)  
    { 
      cv->cv_tot_len <<= EXPANED_VAL; 
      cv->cv_pdata = pd_sav; 
      return CVEPOPBACK; 
    } 
  } 
 
  return CVESUCCESS; 
} 
 
size_t cvector_iter_at(const cvector cv, citerator iter) 
{ 
  CWARNING_ITER(cv, iter, __FILE__, __func__, __LINE__); 
  return (iter - cv->cv_pdata) / cv->cv_size; 
} 
 
int cvector_iter_val(const cvector cv, citerator iter, void *memb) 
{ 
  CWARNING_ITER(cv, iter, __FILE__, __func__, __LINE__); 
  memcpy(memb, iter, cv->cv_size); 
  return 0; 
} 
 
citerator cvector_begin(const cvector cv) 
{ 
  return cv->cv_pdata; 
} 
 
citerator cvector_end(const cvector cv) 
{ 
  return cv->cv_pdata + (cv->cv_size * cv->cv_len); 
} 
 
static inline void cvmemove_foreward(const cvector cv, void *from, void *to) 
{ 
  size_t size = cv->cv_size; 
  void *p; 
  for (p = to; p >= from; p -= size) memcpy(p + size, p, size); 
  return; 
} 
 
static inline void cvmemove_backward(const cvector cv, void *from, void *to) 
{ 
  memcpy(from, from + cv->cv_size, to - from); 
  return; 
} 
 
int cvector_insert(const cvector cv, citerator iter, void *memb) 
{ 
  CWARNING_ITER(cv, iter, __FILE__, __func__, __LINE__); 
 
  if (cv->cv_len >= cv->cv_tot_len)  
  { 
    void *pd_sav = cv->cv_pdata; 
    cv->cv_tot_len <<= EXPANED_VAL; 
    cv->cv_pdata = realloc(cv->cv_pdata, cv->cv_tot_len * cv->cv_size); 
 
    if (!cv->cv_pdata)  
    { 
      cv->cv_pdata = pd_sav; 
      cv->cv_tot_len >>= EXPANED_VAL; 
      return CVEINSERT; 
    } 
  } 
 
  cvmemove_foreward(cv, iter, cv->cv_pdata + cv->cv_len * cv->cv_size); 
  memcpy(iter, memb, cv->cv_size); 
  cv->cv_len++; 
 
  return CVESUCCESS; 
} 
 
int cvector_insert_at(const cvector cv, size_t index, void *memb) 
{ 
  citerator iter; 
 
  if (index >= cv->cv_tot_len)  
  { 
    cv->cv_len = index + 1; 
    while (cv->cv_len >= cv->cv_tot_len) cv->cv_tot_len <<= EXPANED_VAL; 
    cv->cv_pdata = realloc(cv->cv_pdata, cv->cv_tot_len * cv->cv_size); 
    iter = cv->cv_pdata + cv->cv_size * index; 
    memcpy(iter, memb, cv->cv_size); 
  } 
  else  
  { 
    iter = cv->cv_pdata + cv->cv_size * index; 
    cvector_insert(cv, iter, memb); 
  } 
 
  return 0; 
} 
 
citerator cvector_next(const cvector cv, citerator iter) 
{ 
  return iter + cv->cv_size; 
} 
 
int cvector_val(const cvector cv, citerator iter, void *memb) 
{ 
  memcpy(memb, iter, cv->cv_size); 
  return 0; 
} 
 
int cvector_val_at(const cvector cv, size_t index, void *memb) 
{ 
  memcpy(memb, cv->cv_pdata + index * cv->cv_size, cv->cv_size); 
  return 0; 
} 
 
int cvector_rm(const cvector cv, citerator iter) 
{ 
  citerator from; 
  citerator end; 
  CWARNING_ITER(cv, iter, __FILE__, __func__, __LINE__); 
  from = iter; 
  end = cvector_end(cv); 
  memcpy(from, from + cv->cv_size, end - from); 
  cv->cv_len--; 
 
  if ((cv->cv_tot_len >= (MIN_LEN << REDUSED_VAL)) 
      && (cv->cv_len <= (cv->cv_tot_len >> REDUSED_VAL)))  
  { 
    void *pd_sav = cv->cv_pdata; 
    cv->cv_tot_len >>= EXPANED_VAL; 
    cv->cv_pdata = realloc(cv->cv_pdata, cv->cv_tot_len * cv->cv_size); 
 
    if (!cv->cv_pdata)  
    { 
      cv->cv_tot_len <<= EXPANED_VAL; 
      cv->cv_pdata = pd_sav; 
      return CVERM; 
    } 
  } 
 
  return CVESUCCESS; 
} 
 
int cvector_rm_at(const cvector cv, size_t index) 
{ 
  citerator iter; 
  iter = cv->cv_pdata + cv->cv_size * index; 
  CWARNING_ITER(cv, iter, __FILE__, __func__, __LINE__); 
  return cvector_rm(cv, iter); 
} 
 
void cv_info(const cvector cv) 
{ 
  printf("/n/ntot :%s : %d/n", __func__, cv->cv_tot_len); 
  printf("len :%s : %d/n",   __func__, cv->cv_len); 
  printf("size:%s : %d/n/n",  __func__, cv->cv_size); 
  return; 
} 
 
void cv_print(const cvector cv) 
{ 
  int num; 
  citerator iter; 
 
  if (cvector_length(cv) == 0) 
    fprintf(stderr, "file:%s func:%s line:%d error, null length cvector!!/n", __FILE__, __func__, __LINE__); 
 
  for (iter = cvector_begin(cv);  
      iter != cvector_end(cv); 
      iter = cvector_next(cv, iter))  
  { 
    cvector_iter_val(cv, iter, &num); 
    printf("var:%d at:%d/n", num, cvector_iter_at(cv, iter)); 
  } 
 
  return; 
} 

改进版
上面那份代码是在Linux下写的,如果是在Windows的Visul C++环境下编译似乎会出些问题,所以特别做了个改进版:
下面是更新后的代码:

cvector.h

# ifndef __CVECTOR_H__ 
# define __CVECTOR_H__ 
 
# include <stdio.h>  
# include <stdlib.h>  
# include <string.h>  
 
# define MIN_LEN 256 
# define CVEFAILED -1 
# define CVESUCCESS 0 
# define CVEPUSHBACK 1 
# define CVEPOPBACK 2 
# define CVEINSERT  3 
# define CVERM    4 
# define EXPANED_VAL 1 
# define REDUSED_VAL 2 
 
typedef void *citerator; 
typedef struct _cvector *cvector; 
 
# ifdef __cplusplus 
extern "C" { 
# endif 
 
  cvector  cvector_create  (const size_t size              ); 
  void   cvector_destroy (const cvector cv              ); 
  size_t  cvector_length  (const cvector cv              ); 
  int    cvector_pushback (const cvector cv, void *memb        ); 
  int    cvector_popback (const cvector cv, void *memb        ); 
  size_t  cvector_iter_at (const cvector cv, citerator iter      ); 
  int    cvector_iter_val (const cvector cv, citerator iter, void *memb); 
  citerator cvector_begin  (const cvector cv              ); 
  citerator cvector_end   (const cvector cv              ); 
  citerator cvector_next   (const cvector cv, citerator iter      ); 
  int    cvector_val_at  (const cvector cv, size_t index, void *memb ); 
  int    cvector_insert  (const cvector cv, citerator iter, void *memb); 
  int    cvector_insert_at(const cvector cv, size_t index, void *memb ); 
  int    cvector_rm    (const cvector cv, citerator iter      ); 
  int    cvector_rm_at  (const cvector cv, size_t index       ); 
 
  /* for test */ 
  void   cv_info     (const cvector cv              ); 
  void   cv_print     (const cvector cv              ); 
 
# ifdef __cplusplus 
} 
# endif 
 
#endif /* EOF file cvector.h */ 

cvector.c

#include "cvector.h" 
 
#ifndef __gnu_linux__ 
#define __func__ "unknown" 
#define inline __forceinline 
#endif 
 
# define CWARNING_ITER(cv, iter, file, func, line) \ 
  do {\ 
  if ((cvector_begin(cv) > iter) || (cvector_end(cv) <= iter)) {\ 
  fprintf(stderr, "var(" #iter ") warng out of range, "\ 
  "at file:%s func:%s line:%d!!\n", file, func, line);\ 
  return CVEFAILED;\ 
  }\ 
  } while (0) 
 
struct _cvector 
{ 
  void *cv_pdata; 
  size_t cv_len, cv_tot_len, cv_size; 
}; 
 
cvector cvector_create(const size_t size) 
{ 
  cvector cv = (cvector)malloc(sizeof (struct _cvector)); 
 
  if (!cv) return NULL; 
 
  cv->cv_pdata = malloc(MIN_LEN * size); 
 
  if (!cv->cv_pdata) 
  { 
    free(cv); 
    return NULL; 
  } 
 
  cv->cv_size = size; 
  cv->cv_tot_len = MIN_LEN; 
  cv->cv_len = 0; 
 
  return cv; 
}  
 
void cvector_destroy(const cvector cv)  
{  
  free(cv->cv_pdata);  
  free(cv);  
  return;  
}  
 
size_t cvector_length(const cvector cv)  
{  
  return cv->cv_len;  
}  
 
int cvector_pushback(const cvector cv, void *memb)  
{  
  if (cv->cv_len >= cv->cv_tot_len)   
  {  
    void *pd_sav = cv->cv_pdata;  
    cv->cv_tot_len <<= EXPANED_VAL;  
    cv->cv_pdata = realloc(cv->cv_pdata, cv->cv_tot_len * cv->cv_size);  
 
    if (!cv->cv_pdata)   
    {  
      cv->cv_pdata = pd_sav;  
      cv->cv_tot_len >>= EXPANED_VAL;  
      return CVEPUSHBACK;  
    }  
  }  
 
  memcpy((char *)cv->cv_pdata + cv->cv_len * cv->cv_size, memb, cv->cv_size);  
  cv->cv_len++;  
 
  return CVESUCCESS;  
}  
 
int cvector_popback(const cvector cv, void *memb)  
{  
  if (cv->cv_len <= 0) return CVEPOPBACK;  
 
  cv->cv_len--;  
  memcpy(memb, (char *)cv->cv_pdata + cv->cv_len * cv->cv_size, cv->cv_size);  
 
  if ((cv->cv_tot_len >= (MIN_LEN << REDUSED_VAL))   
    && (cv->cv_len <= (cv->cv_tot_len >> REDUSED_VAL)))   
  {  
    void *pd_sav = cv->cv_pdata;  
    cv->cv_tot_len >>= EXPANED_VAL;  
    cv->cv_pdata = realloc(cv->cv_pdata, cv->cv_tot_len * cv->cv_size);  
 
    if (!cv->cv_pdata)   
    {  
      cv->cv_tot_len <<= EXPANED_VAL;  
      cv->cv_pdata = pd_sav;  
      return CVEPOPBACK;  
    }  
  }  
 
  return CVESUCCESS;  
}  
 
size_t cvector_iter_at(const cvector cv, citerator iter)  
{  
  CWARNING_ITER(cv, iter, __FILE__, __func__, __LINE__);  
  return ((char *)iter - (char *)cv->cv_pdata) / cv->cv_size;  
}  
 
int cvector_iter_val(const cvector cv, citerator iter, void *memb)  
{  
  CWARNING_ITER(cv, iter, __FILE__, __func__, __LINE__);  
  memcpy(memb, iter, cv->cv_size);  
  return 0;  
}  
 
citerator cvector_begin(const cvector cv)  
{  
  return cv->cv_pdata;  
}  
 
citerator cvector_end(const cvector cv)  
{  
  return (char *)cv->cv_pdata + (cv->cv_size * cv->cv_len);  
}  
 
static inline void cvmemove_foreward(const cvector cv, void *from, void *to)  
{  
  size_t size = cv->cv_size;  
  char *p;  
  for (p = (char *)to; p >= (char *)from; p -= size) memcpy(p + size, p, size);  
  return;  
}  
 
static inline void cvmemove_backward(const cvector cv, void *from, void *to)  
{  
  memcpy(from, (char *)from + cv->cv_size, (char *)to - (char *)from);  
  return;  
}  
 
int cvector_insert(const cvector cv, citerator iter, void *memb)  
{  
  CWARNING_ITER(cv, iter, __FILE__, __func__, __LINE__);  
 
  if (cv->cv_len >= cv->cv_tot_len)   
  {  
    void *pd_sav = cv->cv_pdata;  
    cv->cv_tot_len <<= EXPANED_VAL;  
    cv->cv_pdata = realloc(cv->cv_pdata, cv->cv_tot_len * cv->cv_size);  
 
    if (!cv->cv_pdata)   
    {  
      cv->cv_pdata = pd_sav;  
      cv->cv_tot_len >>= EXPANED_VAL;  
      return CVEINSERT;  
    }  
  }  
 
  cvmemove_foreward(cv, iter, (char *)cv->cv_pdata + cv->cv_len * cv->cv_size);  
  memcpy(iter, memb, cv->cv_size);  
  cv->cv_len++;  
 
  return CVESUCCESS;  
}  
 
int cvector_insert_at(const cvector cv, size_t index, void *memb)  
{  
  citerator iter;  
 
  if (index >= cv->cv_tot_len)   
  {  
    cv->cv_len = index + 1;  
    while (cv->cv_len >= cv->cv_tot_len) cv->cv_tot_len <<= EXPANED_VAL;  
    cv->cv_pdata = realloc(cv->cv_pdata, cv->cv_tot_len * cv->cv_size);  
    iter = (char *)cv->cv_pdata + cv->cv_size * index;  
    memcpy(iter, memb, cv->cv_size);  
  }  
  else   
  {  
    iter = (char *)cv->cv_pdata + cv->cv_size * index;  
    cvector_insert(cv, iter, memb);  
  }  
 
  return 0;  
}  
 
citerator cvector_next(const cvector cv, citerator iter)  
{  
  return (char *)iter + cv->cv_size;  
}  
 
int cvector_val(const cvector cv, citerator iter, void *memb)  
{  
  memcpy(memb, iter, cv->cv_size);  
  return 0;  
}  
 
int cvector_val_at(const cvector cv, size_t index, void *memb)  
{  
  memcpy(memb, (char *)cv->cv_pdata + index * cv->cv_size, cv->cv_size);  
  return 0;  
}  
 
int cvector_rm(const cvector cv, citerator iter)  
{  
  citerator from;  
  citerator end;  
  CWARNING_ITER(cv, iter, __FILE__, __func__, __LINE__);  
  from = iter;  
  end = cvector_end(cv);  
  memcpy(from, (char *)from + cv->cv_size, (char *)end - (char *)from);  
  cv->cv_len--;  
 
  if ((cv->cv_tot_len >= (MIN_LEN << REDUSED_VAL))  
    && (cv->cv_len <= (cv->cv_tot_len >> REDUSED_VAL)))   
  {  
    void *pd_sav = cv->cv_pdata;  
    cv->cv_tot_len >>= EXPANED_VAL;  
    cv->cv_pdata = realloc(cv->cv_pdata, cv->cv_tot_len * cv->cv_size);  
 
    if (!cv->cv_pdata)   
    {  
      cv->cv_tot_len <<= EXPANED_VAL;  
      cv->cv_pdata = pd_sav;  
      return CVERM;  
    }  
  }  
 
  return CVESUCCESS;  
}  
 
int cvector_rm_at(const cvector cv, size_t index)  
{  
  citerator iter;  
  iter = (char *)cv->cv_pdata + cv->cv_size * index;  
  CWARNING_ITER(cv, iter, __FILE__, __func__, __LINE__);  
  return cvector_rm(cv, iter);  
}  
 
void cv_info(const cvector cv)  
{  
  printf("\n\ntot :%s : %d\n", __func__, cv->cv_tot_len);  
  printf("len :%s : %d\n",   __func__, cv->cv_len);  
  printf("size:%s : %d\n\n",  __func__, cv->cv_size);  
  return;  
}  
 
void cv_print(const cvector cv)  
{  
  int num;  
  citerator iter;  
 
  if (cvector_length(cv) == 0)  
    fprintf(stderr, "file:%s func:%s line:%d error, null length cvector!!\n", __FILE__, __func__, __LINE__);  
 
  for (iter = cvector_begin(cv);   
    iter != cvector_end(cv);  
    iter = cvector_next(cv, iter))   
  {  
    cvector_iter_val(cv, iter, &num);  
    printf("var:%d at:%d\n", num, cvector_iter_at(cv, iter));  
  }  
 
  return;  
}  

main.cpp

#include "cvector.h" 
 
int main() 
{ 
  int i = 1; 
  cvector cv = cvector_create(sizeof(int)); 
  cvector_pushback(cv, &i); 
  cvector_pushback(cv, &i); 
  cvector_pushback(cv, &i); 
  cvector_pushback(cv, &i); 
  cv_print(cv); 
  cvector_destroy(cv); 
  return 0; 
} 

相关文章

  • 实例讲解C++编程中lambda表达式的使用

    实例讲解C++编程中lambda表达式的使用

    这篇文章主要介绍了C++编程中lambda表达式的使用实例,lambda表达式特性的引入在C++11中可谓千呼万唤始出来,非常重要,需要的朋友可以参考下
    2016-01-01
  • C++模板二段名字查找方法

    C++模板二段名字查找方法

    下面小编就为大家带来一篇C++模板二段名字查找方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-01-01
  • C++实现随机生成迷宫地牢

    C++实现随机生成迷宫地牢

    这篇文章主要介绍了C++实现随机生成迷宫地牢的相关资料及代码分享,推荐给大家,有需要的小伙伴可以参考下。
    2015-03-03
  • 使用C语言求解扑克牌的顺子及n个骰子的点数问题

    使用C语言求解扑克牌的顺子及n个骰子的点数问题

    这篇文章主要介绍了使用C语言求解扑克牌的顺子及n个骰子的点数问题的方法,解答实例主要为了突出解题的算法,需要的朋友可以参考下
    2016-03-03
  • 解析C++ 浮点数的格式化显示

    解析C++ 浮点数的格式化显示

    本篇文章是对C++中浮点数的格式化显示进行了详细的分析介绍,需要的朋友参考下
    2013-05-05
  • opencv3/C++ PHash算法图像检索详解

    opencv3/C++ PHash算法图像检索详解

    今天小编就为大家分享一篇opencv3/C++ PHash算法图像检索详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-12-12
  • C++拷贝构造函数(深拷贝与浅拷贝)详解

    C++拷贝构造函数(深拷贝与浅拷贝)详解

    深拷贝和浅拷贝可以简单理解为:如果一个类拥有资源,当这个类的对象发生复制过程的时候,资源重新分配,这个过程就是深拷贝,反之,没有重新分配资源,就是浅拷贝
    2013-09-09
  • QT QML的元素布局的实现

    QT QML的元素布局的实现

    这篇文章主要介绍了QT QML的元素布局的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-02-02
  • C语言实现简单万年历

    C语言实现简单万年历

    这篇文章主要为大家详细介绍了C语言实现简单万年历,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-02-02
  • 使用C++实现顺序链表

    使用C++实现顺序链表

    今天小编就为大家分享一篇关于使用C++实现顺序链表,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2018-12-12

最新评论