我尝试使用Struct在C中创建LinkedList数据结构。下面我有两个例子,一个有效,另一个没有。
首先,python版本是我尝试用C(在python下面)重新创建的,是的,这是代码的和平工作。我试图让我的C版本工作,但我不确定它有什么问题。有人可以尝试解决我的问题吗?甚至提供更好的解决方案?提前谢谢!
class Node:
pass
start = Node()
point = start
point.val = 1
point.next = Node()
point = point.next
point.val = 2
point.next = Node()
point = point.next
point.val = 3
point.next = None
#include <stdio.h>
struct Node {
struct Node *next;
int val;
};
int main() {
struct Node start;
struct Node pointer = start;
int i;
for (i = 0; i < 4; i++) {
struct Node another;
another.val = i;
pointer.next = &another;
pointer = *(pointer.next);
}
pointer = start;
// Print out the value
for (i = 0; i < 4; i++) {
printf("%d\n", pointer.val);
pointer = *(pointer.next);
}
return 0;
}
答案 0 :(得分:0)
$sql= $this->db->query($sql);
$data['brunches'] = $sql->result();