#include using namespace std; /* 1. zamienia co 2 miejsce 2. do funkcji x, i to co przed x na koniec 3. zamiana parami */ struct node { int val; node *next; }; void add(node *&H, int x) { node *p = new node; p->val = x; p->next = H; H = p; } void show(node *H) { cout << "H->"; node *p = H; while (p != NULL) { cout << p->val << "->"; p = p->next; } cout << "NULL\n"; cout << endl; } void del(node *&H) { if (H != 0) { node *p = H; H = H->next; delete p; } cout << endl; } void parzystaPo(node *&H) { if (H != NULL) { node *tmp = H; while (tmp->next!= NULL) { node *p = new node; p->val = tmp->next->val; p->next = tmp->next; tmp->next = p; tmp = p->next->next; } } } void wyrzucPrzed(node *&H, int x) { node *p = H; node *szuk = new node; while (H != NULL) { if (p->val == x) { szuk->val = x; } else p = p->next; } while (H != NULL) { node *koniec = new node; koniec->next = NULL; koniec->val = x; p = H; if (p) { while (p->next) p = p->next; p->next = koniec; } else H = koniec; } } int main() { node *H = NULL; int n; cout << "Ile elementow utworzymy? : "; cin >> n; for (int i = 0; i < n; i++) { int y; cout << "Podaj liczbe: "; cin >> y; add(H, y); } /*int x; cout << "Z przed jakiej liczby wyrzucic na koniec: "; cin >> x; */ show(H); parzystaPo(H); show(H); system("pause"); }