Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Sparse Arrays

Name: Anonymous 2011-12-23 0:08

Alright /proglodites/, let's hear how all of you implement a sparse arrays that stores two-dimensional data.

Name: Anonymous 2011-12-24 3:55


#include "void.h"
typedef struct sparsearray {
  u2 n;
  u2 size;
  u2 *nn;
  void **array;
}fagarray;

fagarray *new_faga(u2 n) {
  fagarray *f = malloc(sizeof(faga));
  f->n = n;
  f->size = 0;
  f->nn = calloc(0,sizeof(int)*n);
  f->array = calloc(NULL,sizeof(void *));
  return f;
}

void addnode(fagarray *f,u2 n,u2 c){
  f->nn[size] = n;
  f->array[size] = malloc(sizeof(n*c));
  size++;
}

void remnode(fagarray *f,u1 f){
  if(f) for i to f->n forb
          free(f->array[size][i]);
        fore
  free(f->array[size]);
  f->nn[size] = 0;
  size--;
}




amidoinitrite?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List