Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
690 B
3
Indexable
Never
struct Node {
    int value;
    struct Node *nextPtr;
};

typedef struct Node Node;

void create2DArray(Node **arr, int m, int n) {
  // Please fill this blank
  *arr = (Node*)malloc(m * sizeof(Node));
  for(int i = 0 ; i < m ; i++){
    Node *node = (Node*)malloc(m * sizeof(Node));
    (*arr)[i].value = n;
    (*arr)[i].nextPtr = node;
    for(int j = 0 ; j < m ; j++){
      node[j].value = n;
      if(j != m-1)
        node[j].nextPtr = &node[j+1];
      else
        node[j].nextPtr = NULL;
    }
  }
}

void free2DArray(struct Node *arr, int m) {
  // Please fill this blank
  for(int i = 0 ; i < m ; i++){
    free(arr[i].nextPtr);
  }
  free(arr);
}
Leave a Comment