Jump to content

Ordonare Alfabetica - Structura C++


GodsOtherHand

Recommended Posts

Buna, am urmatoarea structura:

struct produs

{

	int activ; //+1=produs existent, -1=sters

	char denumire[20];

	char producator[20];

	float pret_cumparare;

	float pret_vanzare;

	int cantitate;

	char caracteristici[55][55];

};	

struct produs ps[50];

int index; // memoreaza cate "produse" am introdus in structura

ma poate ajuta cineva sa afisez acea structura in ordine alfabetica dupa campul "Denumire" ?

Mam gandit sa iau o variabila "Minim" care sa retina cuvantul cel mai mic (cu strcmp), dar nam idee cum sa treac dupaia la urmatorul..

Orice idee e binevenita :) Multumesc

love is a verb
Love is a doing word

Link to comment
Share on other sites

Apoi o functie care iti returneaza o valoare int ordoneaza(struct persoana p[], int n) {int i,j, val=1; for(i=0; i<n-1 si ord; i++) if strcmp de p.denumire, p[i+1].denumire >0 val=0; if(!val) { for (i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(strcmp de p.denumire, p[j].denumire>0) schimba(adres ap, adresa p[j]); } return (!val);}

  • Upvote 1
Link to comment
Share on other sites

thx.. eu ma gandeam cum sa le ordonez fara sa le schimb ordinea initiala, dar acu ca ai zis asa..nu ma opreste nimeni sa le pun in ce ordine vreau.

Thx :D

app, ca sa ma asigur ca e ordonata.. trebuie parcurs de index * index ori, nu? (index imi arata cate elemente am)

love is a verb
Love is a doing word

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.