Infocplusplus
Infocplusplus
#include<iostream>
struct nod
{
int x;
struct nod* next,*p,*c,*u;
}
int n,i;
void creare()
{
cout<<"Dati nr de inregistrari=";
cin>>n;
cin>>c->x;
c->next=0;
p=c;
u=c;
for(i=2; i<=n; i++)
{
cin>>c->x;
c->next=0;
u->next=c;
u=c;
}
}
void listare()
{
c=p;
while(c)
{
cout<<c->x<<" ";
c=c->next;
}
}
void interclasare()
{
struct nod *c1,*c2,*c3;
c1=p1;
c2=p2;
if(c1->x<c2->x)
{
c3->x=c1->x;
c1=c1->next;
}
else
{
c3->x=c2->x;
c2=c2->next;
}
c3->next=0;
p3=c3;
u3=c3;
while(c1&&c2)
if(c1->x<c2->x)
{
c3->x=c1->x;
c3->next=0;
u3->next=c3;
u3=c3;
c1=c1->next;
}
else
{
c3->x=c2->x;
c3->next=0;
u3->next=c3;
u3=c3;
c2=c2->next;
}
if(!c1)
while(c2)
{
c3->x=c2->x;
c3->next=0;
u3->next=c3;
u3=c3;
c2=c2->next;
}
if(!c2)
while(c1)
{
c3->x=c1->x;
c3->next=0;
u3->next=c3;
u3=c3;
c1=c1->next;
}
c3=p3;
while(c3)
{
cout<<c3->x<<" ";
c3=c3->next;
}
void main()
{
creare();
listare();
interclasare();
listare();
return 0;
}
Sortare insertie:
#include <iostream>
struct nod {
int val;
struct nod* next;
};
nou->next = curent->next;
curent->next = nou;
}
}
insert(&listaSortata, curent->val);
curent = urmator;
}
*p = listaSortata;
}
sortarePrinInsertie(&p);
return 0;
}
Inverse leg:
#include<fstream>
ifstream f("date.in");
ofstream g("date.out");
struct nod
{
int info;
nod *leg;
};
nod *prim;
void main()
{
creare();
afis(prim);
invers(prim);
afis(prim);
}