Advertisement
jeicamad

Untitled

Mar 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. struct node {
  6. int val;
  7. node* next;
  8. };
  9. void Add(node*&, double);
  10. void Show(node*);
  11. void LoadList(node*&);
  12. void Swap(node*&);
  13.  
  14. int main()
  15. {
  16. node *H = NULL;
  17. LoadList(H);
  18. Show(H);
  19. cout << endl;
  20. Swap(H);
  21. Show(H);
  22.  
  23. system("PAUSE");
  24. return 0;
  25. }
  26.  
  27. void Add(node*& Head, double x) {
  28. node* p = new node;
  29. p->val = x;
  30.  
  31. p->next = Head;
  32. Head = p;
  33. }
  34. void Show(node * Head) {
  35. node* p = Head;
  36. while (p != NULL) {
  37. cout << p->val << " ";
  38. p = p->next;
  39. }
  40. }
  41. void LoadList(node *&Head) {
  42. double tmp;
  43. fstream plik;
  44. plik.open("D:\\Liczby.txt", std::ios::in | std::ios::out);
  45. if (plik.good() == true)
  46. {
  47. while (!plik.eof()) {
  48. plik >> tmp;
  49. Add(Head, tmp);
  50. }
  51. plik.close();
  52. }
  53. }
  54.  
  55. void Swap(node *&Head) {
  56. node* p = Head;
  57. node* q = p->next;
  58.  
  59. p->next = q->next;
  60. q->next = Head;
  61. Head = q;
  62. p = q;
  63. q = Head;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement