4TH

SINGLE LINK LIST 1

4TH
Apr 2nd, 2026
4
0
Never
Not a member of GistPad yet? Sign Up, it unlocks many cool features!
C++ (WinAPI) 6.20 KB | Source Code | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. struct Node
  4. {
  5. int data;
  6. Node*next;
  7. };
  8. // Head pointer
  9. Node*head=NULL;
  10. // Function to insert at end
  11. void insertEnd(int value)
  12. {
  13. Node*newNode=new Node();
  14. newNode->data=value;
  15. newNode->next=NULL;
  16. if (head == NULL)
  17. {
  18. head = newNode;
  19. return;
  20. }
  21. Node*temp=head;
  22. while(temp->next!= NULL)
  23. {
  24. temp=temp->next;
  25. }
  26. temp->next=newNode;
  27. }
  28. // Function to display list
  29. void display()
  30. {
  31. Node*temp = head;
  32. cout<< "Linked List: ";
  33. while(temp!= NULL)
  34. {
  35. cout<<temp->data<"->";
  36. temp=temp->next;
  37. cout << "NULL\n";
  38. }
  39. int main()
  40. {
  41. insertEnd(10);
  42. insertEnd(20);
  43. insertEnd(30);
  44. display();
  45. return 0;
  46. }
RAW Paste Data Copied