Write your question here.
i need to add a bubble sort to this code and i coudn't do it,please a save from someone i need it in two and half hours from now
# include <iostream>
#define T=5
usingnamespace std;
int arrays(int number1[],int number2[])
{
int x=5,i,a,b=0;
for (i=0;i<5;i++)
{
for (a=0;a<x;a++)
{
if (number1[i]==number2[a])
{
number2[a]=number2[x];
number1[i]=number1[x];
x--;
a--;
b++;
continue;
}
}
if (number1[i]==number2[a])
{number1[i]=number1[x];
x--;
a--;
b++;
continue;
}
}
return x;}
int main ()
{
int x,i,a,num1[5],num2[5],b=0;
cout<< "Please enter 5 intigers: "<<endl;
for (i=0;i<5;i++)
{
cin>> num1[i];}
cout<< "Please enter another 5 intigers: "<<endl;
for (a=0;a<5;a++)
{
cin>> num2[a];
}
x=arrays(num1,num2);
if (x==0)
{
cout <<"This arrays have same numbers "<<endl;
}
else
{
cout <<"This arrays dose not have same numbers "<<endl;
}
return 0;
}
i know usually i am studying what i am being told but they didn't taught us that and this is new and i two hours to figure this out please mate help me with that
i have tried to use the simple command if(swap())
without any success
Okay so swap is where you started to have trouble?
Here is how to swap two integers:
1 2 3 4 5 6 7
int a=5, b=2;
int temp; //we need a temporary location to store a copy
temp = a; //store the first number to the temporary location
a = b; //overwrite the first number with the second
//it is okay to overwrite because the temporary location has a copy
b = temp; //the two numbers are now officially swapped
The goal of bubble sort is to search the part of the list that is not sorted yet for the biggest or smallest element. Take that element and put it on the end of the sorted part of the list by "bubbling" the element to the correct spot.
i have tried now to put it in the code without any success, sorry bro i am too tired and this is new thing for mem i set on Hw all day long i am going to upload it like that,thank you for trying to help me