DATA STRUCTURE practice
- // data structure ---- linked list-3 C language
- #include <stdio.h>
- #include <stdlib.h>
- using namespace std;
- int main()
- {
- typedef struct list_node *list_pointer;
- typedef struct list_node{
- int data;
- list_pointer link;
- }listNode;
- // declare variables
- list_pointer first,second,third,temp;
- first = (list_pointer)malloc(sizeof(listNode));
- second = (list_pointer)malloc(sizeof(listNode));
- third = (list_pointer)malloc(sizeof(listNode));
- temp = (list_pointer)malloc(sizeof(listNode));
- // data
- first -> data = 10;
- second -> data = 20;
- temp -> data = 30;
- third -> data = 40;
- // link
- first -> link = second;
- second -> link = third;
- third -> link = NULL;
- printf("%d",second->link);
- printf("\n");
- printf("%d",third->link);
- free(first);
- free(second);
- free (third);
- free(temp);
- }
留言
張貼留言