fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Node{
  5. int data;
  6. public:
  7. Node* next;
  8. void setData(int val){
  9. data = val;
  10. }
  11. int getData(){
  12. return data;
  13. }
  14. Node* getNext(){
  15. return next;
  16. }
  17. };
  18.  
  19. void addNode(Node** head, int data){
  20. Node* temp = new Node;
  21. temp->setData(data);
  22. temp->next = *head;
  23. *head = temp;
  24. }
  25.  
  26. void printNode(Node** head){
  27. while(*head != NULL)
  28. {
  29. cout<<(*head)->getData()<<endl;
  30. *head = (*head)->getNext();
  31. }
  32. }
  33.  
  34. void reverse(Node** node){
  35.  
  36. }
  37.  
  38. int main() {
  39. // your code goes here
  40. Node* head = NULL;
  41. addNode(&head, 1);
  42. addNode(&head, 2);
  43. addNode(&head, 3);
  44. addNode(&head, 4);
  45. addNode(&head, 5);
  46.  
  47. printNode(&head);
  48. return 0;
  49. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
5
4
3
2
1