data strucure

  1. // data structure ---- linked list-2
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. using namespace std;
  6. int main()
  7. {
  8. typedef struct list_node* list_pointer;       // create another name for list_node called list_pointer  
  9. typedef struct list_node
  10.     {
  11.     int data ;
  12.     list_pointer link;
  13.     } ListNode;
  14. //Variable
  15. list_pointer first, second;
  16. first = (list_pointer) malloc(sizeof(ListNode));
  17. second = (list_pointer) malloc(sizeof(ListNode));
  18. second -> link = NULL;
  19. second -> data = 20;
  20. first -> data = 10;
  21. first ->link = second;
  22. printf("%d",first-> data);
  23. printf("%3d",second->data);
  24. free(first);
  25. free(second);
  26. }

留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change

codeforces 271A --- beautiful year