struct ListNode {
    int element;
    struct ListNode *next;
};
void printList(ListNode *head) {
    if (head != nil) {
        if (head->next != nil) {
            printList(head->next);
        }
        printf("%d\t", head->element);
    }
}
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        ListNode *head = (ListNode *)malloc(sizeof(ListNode));
        ListNode *one = (ListNode *)malloc(sizeof(ListNode));
        ListNode *two = (ListNode *)malloc(sizeof(ListNode));
        ListNode *three = (ListNode *)malloc(sizeof(ListNode));
        head->element = 0;
        one->element = 1;
        two->element = 2;
        three->element = 3;
        head->next = one;
        one->next = two;
        two->next = three;
        three->next = nil;
        printList(head);
    }
    return 0;
}
网友评论