DATA STRUCTURE practice

  1. // data structure ---- linked list-3       C language
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. using namespace std;
  5. int main()
  6. {
  7. typedef struct list_node *list_pointer;
  8. typedef struct list_node{
  9. int data;
  10. list_pointer link;     
  11. }listNode; 
  12. // declare variables
  13. list_pointer first,second,third,temp;
  14. first = (list_pointer)malloc(sizeof(listNode));
  15. second = (list_pointer)malloc(sizeof(listNode));
  16. third = (list_pointer)malloc(sizeof(listNode));
  17. temp = (list_pointer)malloc(sizeof(listNode));
  18. // data
  19. first -> data = 10;
  20. second -> data = 20;
  21. temp -> data = 30;
  22. third -> data = 40;
  23. // link
  24. first -> link = second;
  25. second -> link = third;
  26. third -> link = NULL;
  27. printf("%d",second->link); 
  28. printf("\n");
  29. printf("%d",third->link);
  30. free(first);
  31. free(second);
  32. free (third);
  33. free(temp);
  34. }

留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change

codeforces 271A --- beautiful year