Advertisement
Timtsa

List_List

Dec 6th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include "Node.h"
  2. #include <iostream>
  3.  
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9. void PrintList(Node*pHead)
  10. {
  11.     for (Node*pCurront = pHead; pCurront != nullptr;pCurront=pCurront->getpNext())
  12.     {
  13.         cout << pCurront->getData() << endl;
  14.     }
  15. }
  16. void AddListHead(const DataType &data, Node*&pHead)
  17. {
  18.    
  19.     Node*pNew = new Node;
  20.     pNew->setData(data);
  21.     pNew->setpNext(pHead);
  22.     pHead = pNew;
  23.  
  24. }
  25.  
  26. int main()
  27. {
  28.    
  29.  
  30.     Node n;
  31.     int a = 3;
  32.     n.setData(a);
  33.     //cout <<  n.getData()<<endl;
  34.     Node*pHead = new Node(1);
  35.     pHead->setpNext(new Node(3));
  36.     PrintList(pHead);
  37.     AddListHead(0, pHead);
  38.     PrintList(pHead);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement