Untitled
unknown
plain_text
a year ago
1.7 kB
7
Indexable
#include <stdio.h> struct Node{ int data; struct Node* next; }; int main() { struct Node* node1; node1 = malloc(sizeof(struct Node)); node1->data = 30; node1->next = NULL; printf("%d ", node1->data); struct Node* node2; node2 = malloc(sizeof(struct Node)); node2->data = 40; node2->next = NULL; node1->next = node2; printf("%d ", node2->data); struct Node* node3; node3= malloc(sizeof(struct Node)); node3->data = 50; node3->next = NULL; node2->next = node3; printf("%d\n", node3->data); struct Node* head = node1; head->data = 100; printf("%d", node1->data); printf("\n===================\n"); printLinkedList(head); printf("\n===================\n"); printLinkedListWhileLoop(head); printf("\n===================\n"); insert(head, 10); } void insert(struct Node* head, int data){ //TODO } void printLinkedList(struct Node* head){ if(head == NULL){ return; } printf("%d ", head->data); struct Node* node2 = head->next; if(node2 == NULL){ return; } printf("%d ", node2->data); struct Node* node3 = node2->next; if(node3 == NULL){ return; } printf("%d ",node3->data); node3->data = 60; printf("\n%d ",node3->data); struct Node* node4 = node3->next; if(node4 == NULL){ return; } printf("%d ",node4->data); } void printLinkedListWhileLoop(struct Node* head){ struct Node* node = head; while(node != NULL){ printf("%d ", node->data); node = node->next; } }
Editor is loading...
Leave a Comment