Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct node {
- int val;
- node* next;
- };
- void Add(node*&, double);
- void Show(node*);
- void LoadList(node*&);
- void Swap(node*&);
- int main()
- {
- node *H = NULL;
- LoadList(H);
- Show(H);
- cout << endl;
- Swap(H);
- Show(H);
- system("PAUSE");
- return 0;
- }
- void Add(node*& Head, double x) {
- node* p = new node;
- p->val = x;
- p->next = Head;
- Head = p;
- }
- void Show(node * Head) {
- node* p = Head;
- while (p != NULL) {
- cout << p->val << " ";
- p = p->next;
- }
- }
- void LoadList(node *&Head) {
- double tmp;
- fstream plik;
- plik.open("D:\\Liczby.txt", std::ios::in | std::ios::out);
- if (plik.good() == true)
- {
- while (!plik.eof()) {
- plik >> tmp;
- Add(Head, tmp);
- }
- plik.close();
- }
- }
- void Swap(node *&Head) {
- node* p = Head;
- node* q = p->next;
- p->next = q->next;
- q->next = Head;
- Head = q;
- p = q;
- q = Head;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement