Cheatography
https://cheatography.com
CITIREA
cout<<"introduceti numarul de elemente din vector" ;
cin>>n;
for(i=0; i<n; i++)
{cout<<"v["<<i<<"]=";
cin>>v[i]
} |
SORTAREA-METODA BULELOR
do
{ ok=0;
for(i=0; i<n; i++)
if (v[i]>v[i+1])
{ aux=v[i];
v[i]=v[i+1];
v[i+1]=aux;
ok=1;
} while (ok==1); |
|
|
DECLARAREA
numele_vectorului[numarul maxim de elemente]
ex. v[100]; |
CAUTAREA UNUI ELEMENT IN VECTOR
for (i=0; i<n; i++)
{ if (x==v[i])
{poz=i;
ok=1;
}
if (ok==1)
cout<<"elementul"<<x<<" se gaseste in vector pe pozitia"<<poz;
else cout<<"elementul"<<x<<"nu se gaseste in vector"; |
|
|
AFISAREA
for (i=0; i<n; i++)
cout<<v[i]; |
CAUTAREA UNUI ELEMENT IN VECTOR-BINAR
i=0;
j=n-1;
while (i<=j)
{mij=(i+j)/2;
if (x==v[mij])
cout<<"elementul"<<x<<"se gaseste in vector pe pozitia"<<mij;
else if (x>v[mij])
i=mij+1;
else j=mij-1;
} |
Vectorul trebuie sa fie ordonat crescator.
INTERCLASAREA A DOI VECTORI
i=0;
j=0;
a[n]=b[m-1]+1;
b[m]=a[n-1]+1;
for (k=0; k<n+m; k++)
if (a[i]<b[j])
c[k]=a[i++];
else c[k]=b[j++]; |
Vetorii trebuie sa fie ordonati crescator.
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by [deleted]