Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "iostream"
- using namespace std;//dupa nota duma nume
- struct Student{
- char nume[20];
- int nota;
- Student *n_nume, *n_nota;//studenti crescatori si node descrescatoare
- };
- void adaugare(Student *&prim_nume, Student *&prim_nota){
- Student *a= new Student;
- cout<<"Nume: ";
- cin>>a->nume;
- cout<<"Nota: ";
- cin>>a->nota;
- if(prim_nume==NULL){
- prim_nume=a;
- a->n_nume=NULL;
- }
- else{
- if(strcmp(a->nume,prim_nume->nume)<0)
- {
- a->n_nume=prim_nume;
- prim_nume=a;
- }
- else{
- Student *p= prim_nume;
- while(p->n_nume!=NULL&&strcmp(p->n_nume->nume,a->nume)<0){
- p=p->n_nume;
- }
- a->n_nume=p->n_nume;
- p->n_nume=a;
- }
- }
- if(prim_nota==NULL){
- prim_nota=a;
- a->n_nota=NULL;
- }
- else{
- if(a->nota>prim_nota->nota){
- a->n_nota=prim_nota;
- prim_nota=a;
- }
- else{
- Student *p= prim_nota;
- while(p->n_nota!=NULL&&p->n_nota->nota>a->nota){
- p=p->n_nota;
- }
- a->n_nota=p->n_nota;
- p->n_nota=a;
- }
- }
- }
- void afisareNota(Student *prim){
- cout<<"Afisare studenti in functie de nota: \n";
- while(prim!=NULL)
- {
- cout<<prim->nume<<": "<<prim->nota<<endl;
- prim=prim->n_nota;
- }
- }
- void afisareNume(Student *prim){
- cout<<"Afisare studenti in functie de nume: \n";
- while(prim!=NULL)
- {
- cout<<prim->nume<<": "<<prim->nota<<endl;
- prim=prim->n_nume;
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- Student *prim_nota=NULL, *prim_nume=NULL;
- int n;
- cout<<"\nIntroduceti un numar: ";
- cin>>n;
- for (int i = 0; i < n; i++)
- {
- adaugare(prim_nume,prim_nota);
- }
- afisareNota(prim_nota);
- afisareNume(prim_nume);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement