#include #include using namespace std; struct node { int val; node *next; }; void insert(node *&H, int x); void remove(node *&H); void show(node *H); int* ReadDataFromFile(int &size); void swap(node *&H, node *x) { if (x == NULL) { node *p = H; node *tmp = p->next; p->next = tmp->next; H = tmp; tmp->next = p; } else { node *p = x->next; node *tmp = p->next; p->next = tmp->next; tmp->next = p; x->next = tmp; } } void bubble(node *&H) { bool flag = true; while (flag) { node *p = H; node *tmp = NULL; flag = false; if(p->val>p->next->val) { node *pusty = NULL; swap(H, pusty); flag = true; } while (p->next->next != tmp) { if (p->next->val > p->next->next->val) { swap(H, p); flag = true; } p = p->next; } tmp = p; } } node *getLast(node *H) { if (!H) return false; // pusta lista node *tmp = H; while (tmp->next != NULL) tmp = tmp->next; return tmp; } void zlacz(node *&H, node *&x) { node *p = getLast(H); node *tmp = x; p->next = tmp; } int main() { node *H = NULL; int size = 0; int *t = ReadDataFromFile(size); node *listy[50]; for (int i = 0; i < 50; i++) listy[i] = NULL; int i = 0; for (int j = 0; j < 50; j++) for (int k = 0; k < 10; k++) { insert(listy[j], t[i]); i++; } cout << "Podzielone posortowane: " << endl; for (int i = 0; i < 50; i++) { bubble(listy[i]); show(listy[i]); } cout << endl; H = listy[0]; for(int i=1; i<50; i++) zlacz(H, listy[i]); bubble(H); show(H); system("PAUSE"); return 0; } int* ReadDataFromFile(int &size) { fstream czytaj; czytaj.open("liczby.txt"); czytaj >> size; int*Data = new int[size]; for (int i = 0; i> Data[i]; czytaj.close(); return Data; } void insert(node *&H, int x) { node *pom; pom = new node; pom->val = x; pom->next = H; H = pom; } void remove(node *&H) { if (H != NULL) { node *pom = H; H = pom->next; delete pom; } } void show(node *H) { node *pom = H; cout << "HEAD ->"; while (pom != NULL) { cout << pom->val << "->"; pom = pom->next; } cout << "NULL" << endl; }