我试图在C中构建一个基本的链表.我似乎得到这个代码的错误:
typedef struct
{
char letter;
int number;
list_t *next;
}list_t;
char letters[] = {"ABCDEFGH"};
list_t openGame, ruyLopez;
openGame.letter = letters[4];
openGame.number = 4;
openGame.next = &ruyLopez;
ruyLopez.letter = letters[5];
ruyLopez.number = 4;
ruyLopez.next = NULL;
Run Code Online (Sandbox Code Playgroud)
它不接受我在结构中的定义:
list_t *next;
Run Code Online (Sandbox Code Playgroud)
出于同样的原因,它不会接受:
openGame.next = &ruyLopez;
Run Code Online (Sandbox Code Playgroud) 我有一个反向排序的堆。我正在尝试构建最大堆:
我有代码:
int main(int argc, char *argv[])
{
int heapArray[] = {0, 1, 2, 3, 4, 5, 6 , 7, 8 ,9 ,10 , 11, 12, 13 ,14 ,15};
int n = sizeof(heapArray)/sizeof(int);
printTree(heapArray, n);
buildHeap(heapArray, n);
printTree(heapArray, n);
}
void buildHeap(int array[], int n)
{
printf("buildHeap\n");
int i = (n-1)/2;
while(i > 0) heapify(array, n, i--);
}
void heapify(int array[], int n, int i)
{
printf("heapify [%i] = %i\n", i, array[i]);
int childLeft = 0, childRight = 0;
int …Run Code Online (Sandbox Code Playgroud)