Advertisement
hungkt1997

9/5

Sep 5th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. struct node{
  4. int data;
  5. node *next;
  6. };
  7. void main()
  8. {
  9. int i = 1;
  10. int n = 10;
  11. node *pNew = NULL;
  12. node *pHead = new node;
  13. pHead->data = i;
  14. pHead->next = NULL;
  15. while (n-- > 0){
  16. pNew = new node;
  17. pNew->data = ++i;
  18. pNew->next = NULL;
  19. node *pRun = pHead;
  20. while (pRun->next != NULL)
  21. pRun = pRun->next;
  22. pRun->next = pNew;
  23. }
  24. node *pPrint = pHead;
  25. while (pPrint != NULL){
  26. cout << pPrint->data << "->";
  27. pPrint = pPrint->next;
  28. }
  29.  
  30. system("pause");
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement