Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct Complex{
- int real, img;
- Complex(){
- }
- Complex(int r, int i){
- real=r;
- img=i;
- }
- void showStruct(){
- printf("real,img");
- }
- };
- void bubbleSort(Complex* arrayPtr, int length_array) // sortarea prin bule
- {
- Complex temp; // temporar sa salveze masivul
- bool exit = false; // iesire din masiv daca a fost sortat
- while (!exit) // pina cind masivul nu este sortat
- {
- exit = true;
- for (int int_counter = 0; int_counter < (length_array - 1); int_counter++) // ciclu interior
- //sortarea dupa crescator - simbolul >
- //sortarea de la descrescator - simbolul <
- if (arrayPtr[int_counter].img > arrayPtr[int_counter + 1].img) // cmp a 2 elemente de linga
- {
- // sortatrea
- temp = arrayPtr[int_counter];
- arrayPtr[int_counter] = arrayPtr[int_counter + 1];
- arrayPtr[int_counter + 1] = temp;
- exit = false; // iara sortarea din nou
- }
- }
- }
- int main() {
- Complex mas[5];
- int real, img;
- for(int i=0;i<5;i++){
- scanf("%d %d",&real,&img);
- mas[i]=Complex(real, img);
- }
- printf("\n");
- for(int i=0;i<5;i++){
- mas[i].showStruct();
- }
- printf("\n");
- bubbleSort(mas,5);
- for(int i=0;i<5;i++){
- mas[i].showStruct();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement