Advertisement
TawratNibir

ll

Jun 29th, 2025
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. typedef struct node
  5. {
  6.     int value;
  7.     struct node *next;
  8. } node_t;
  9. node_t *head;
  10. node_t *target;
  11. void printList(node_t *head)
  12. {
  13.     node_t *temporary;
  14.     temporary = head;
  15.  
  16.     while (temporary != NULL && temporary->value != INT_MAX)
  17.     {
  18.         printf("%d - ", temporary->value);
  19.         temporary = temporary->next;
  20.     }
  21. }
  22. void insertLinkedList(int temp)
  23. {
  24.     // printf("hello \n");
  25.     target->value = temp;
  26.     node_t *newNode;
  27.     newNode = (node_t *)malloc(sizeof(node_t));
  28.     target->next = newNode;
  29.     target = newNode;
  30.     // printf("hello 2 ");
  31. }
  32. int main()
  33. {
  34.     node_t *first;
  35.     first = (node_t *)malloc(sizeof(node_t));
  36.     head = first;
  37.     target = first;
  38.     // cout << head->next << endl;
  39.     insertLinkedList(5);
  40.     insertLinkedList(4);
  41.     insertLinkedList(3);
  42.     insertLinkedList(2);
  43.     target->value = INT_MAX;
  44.     target->next = NULL;
  45.     target = NULL;
  46.     printList(head);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement