Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct link {
  5. int value;
  6. link * next;
  7. };
  8.  
  9. int main() {
  10.  
  11. link *top;
  12. link *current, *previous;
  13. link *lptr;
  14.  
  15. int ivalue;
  16.  
  17. cout<< "<Input next value, -1 to terminate> \n" <<flush;
  18. cin>> ivalue;
  19.  
  20. top = 0;
  21. //Build the list
  22. while (ivalue != -1) {
  23.  
  24. lptr = new link;
  25. lptr->value = ivalue;
  26. current = top;
  27. previous = 0;
  28.  
  29. //your code here
  30. lptr = top;
  31. while ( top ) {
  32. cout << top->value << ā€™\nā€™;
  33. top = top->next; // top = (*top).next;
  34. delete lptr;
  35. lptr = top;
  36. }
  37.  
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement