Untitled
unknown
c_cpp
a month ago
995 B
1
Indexable
Never
#include <stdio.h> #include <stdlib.h> typedef struct Node { int x; int y; struct Node* next; } Node; int main(int argc, char* argv[]) { Node root; root.y = 1; root.x = 153; root.next = malloc(sizeof(Node)); // same as in len() py root.next->x = -2; root.next->y = 2; root.next->next = malloc(sizeof(Node)); root.next->next->x = 22; root.next->next->y = 19; root.next->next->next = NULL; root.next->next->next = malloc(sizeof(Node)); root.next->next->next->x = -3491; root.next->next->next->y = 2034; root.next->next->next->next = NULL; /* while loop Node* curr = &root; while(curr != NULL){ // linked list loop printf("its: %d\n", curr->x); curr = curr->next; } */ for(Node* curr = &root; curr != NULL; curr = curr->next) { printf("x: %d vs y: %d\n", curr->x, curr->y); //curr = curr->next; } free(root.next->next); free(root.next); return 0; }