#include<iostream>
#include<fstream>
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<size; i++)
czytaj >> 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;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}