Jump to content
hitme

[Liste] c++

Recommended Posts

Se considera o lista dublu inlantuita de studenti cu structura:cod matricol, nume, prenume si media. Sa se scrie programul in C pentru crearea, ordonarea dupa medie si afisarea listei studentilor folosindu-se cate o functie adecvata pentru fiecare operatie (creare, ordonare si listare).

cum pot ordona lista, fara sa permut valorile campurilor?

eu am incercat asa, ceva ideei?

EDIT: am inteles ca se poate ordona cu std::sort, dar nu stiu cum :D


#include <iostream>
#include <stdlib.h>
using namespace std;

struct nod
{
int cod_matricol;
char nume[20];
char prenume[20];
float media;
nod *urmator, *anterior;
};
nod *prim, *ultim,xx;
// int yy=0;

void creez()
{
nod *c;
c=new nod;
cout<<"Cod matricol : "; cin>>c->cod_matricol;
cout<<"Nume : "; cin>>c->nume;
cout<<"Prenume : "; cin>>c->prenume;
cout<<"Media : "; cin>>c->media;

if (!prim)
{
prim=c;
prim->urmator=0;
prim->anterior=0;
ultim=prim;
}
else
{
ultim->urmator=c;
c->anterior=ultim;
ultim=c;
ultim->urmator=0;
}
}

void afisez()
{
nod *c;
int i=1;
c=prim;
while (c)
{
cout<<"Inregistrarea "<<i++<<" : "<<endl;
cout<<"Cod matricol : "<<c->cod_matricol<<endl;
cout<<"Nume : "<<c->nume<<endl;
cout<<"Prenume : "<<c->prenume<<endl;
cout<<"Media : "<<c->media<<endl;
cout<<endl;
c=c->urmator;
}
}

void ordonez()
{
nod *x,*y,*aux;
int auxaux;
aux=prim->urmator;
for(x=prim;x!=0;x=x->urmator)
for(y=aux;y!=0;y=y->urmator)
if(x->media > y->media)
{
xx=*x;
*x=*y;
*y=xx;
*prim=xx;
}
}

int main()
{
int n,i;
cout<<"Cate inregistrari? : "; cin>>n;
for(i=1;i<=n;i++)
creez();
system("cls");
afisez();
system("pause");
system("cls");
ordonez();
afisez();
system("pause");

return 0;
}

Edited by hitme
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...