如何用C语言实现向量操作
就是实现C++里面 vector 的操作
有没有哪位有现成的代码~
多谢了
[解决办法]
哎,怎么可能不分配嘛
要么动态分配
要么静态分配
你没看到人家分配的代码.就一口咬定人家没有分配??
谁家的电脑那么牛B,我拜它做师傅好不好?
你总追求用现成的,你就看不到实现的一些过程
说白了
模版容器就是链表结构的实现
[解决办法]
仅供参考
//使用动态分配#include <stdio.h>#include <stdlib.h>#include <malloc.h>int i,L;char *p;void main() { for (i=0;i<20000;i++) { L=rand(); p=malloc(L); if (NULL==p) { printf("malloc error!\n"); continue; } memset(p,0,L); free(p); }}//不使用动态分配#include <stdio.h>#include <stdlib.h>#include <memory.h>#define MAXLEN 30000int i,L;char buf[MAXLEN];char *p;void main() { p=&buf[0]; for (i=0;i<20000;i++) { L=rand(); if (L>MAXLEN) { printf("L>MAXLEN==%d, ignore spilth.\n",MAXLEN); L=MAXLEN; } memset(p,0,L); }}