Pagini recente » Cod sursa (job #2183523) | Cod sursa (job #62388) | Cod sursa (job #1226594) | Cod sursa (job #404075) | Cod sursa (job #633922)
Cod sursa(job #633922)
#include<iostream>
#include<fstream>
using namespace std;
struct NOD {long double info;
NOD *next;};
int n;
ifstream c("algsort.in");
ofstream d("algsort.out");
NOD* create()
{ NOD *p,*u,*x,*y;
p=0;
u=0;
int i;
for(i=1;i<=n;i++) {
x=new NOD;
c>>x->info;
x->next=0;
if(p==0) {
p=x;
u=x;}
else
if(x->info<p->info)
{ x->next=p;
p=x; }
else
if(x->info>u->info)
{ u->next=x;
u=x; }
else
{y=p;
while(y->next!=0&&x->info>y->next->info)
y=y->next;
x->next=y->next;
y->next=x; }
}
return p; }
void view(NOD *prim)
{NOD *x;
x=prim;
while(x!=0) {
d<<x->info<<" ";
x=x->next;}
}
int main()
{ NOD *l;
c>>n;
l=create();
view(l);
c.close();
d.close(); }