Advertisement
samulohi

Untitled

Feb 22nd, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct Node{
  5. int data;
  6. struct Node *link;
  7.  
  8. };
  9. struct Node*ptr;
  10. void push(int data){
  11. struct Node*temp;
  12. temp=new Node();
  13. temp->data=data;
  14. temp->link=ptr;
  15. ptr=temp;
  16. }
  17. void display()
  18. {
  19. struct Node* temp;
  20.  
  21. if(ptr!=NULL) {
  22. temp = ptr;
  23. while (temp != NULL) {
  24.  
  25. // print node data
  26. cout << temp->data << " ";
  27.  
  28. // assign temp link to temp
  29. temp = temp->link;
  30. }
  31. }
  32. }
  33. int main(){
  34. push(11);
  35. push(22);
  36. push(50);
  37. push(60);
  38. push(70);
  39. display();
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement