0% found this document useful (0 votes)
36 views

Metoda Bulelor: #Include #Include Int I, X (50), N, A, T Int Main

The document discusses and provides code examples for several sorting and searching algorithms, including bubble sort, selection sort, merging two sorted arrays, linear search in a sorted array, and sequential search in an unsorted array. Code snippets are provided in C++ to implement each of these algorithms to sort or search arrays of integers.

Uploaded by

Ionut Moisa
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Metoda Bulelor: #Include #Include Int I, X (50), N, A, T Int Main

The document discusses and provides code examples for several sorting and searching algorithms, including bubble sort, selection sort, merging two sorted arrays, linear search in a sorted array, and sequential search in an unsorted array. Code snippets are provided in C++ to implement each of these algorithms to sort or search arrays of integers.

Uploaded by

Ionut Moisa
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Metoda bulelor

#include<iostrem.h>
#include<conio.h>
Int i, x[50], n, a, t;
int main()
{
cout<<n=;
cin>>n;
for(i=0, i<=n, i++)
{
cout<<x[<<i<<]=;
cin>>x[i];
}
t==0;
while(t==0)
{
t==1;
for(i=0, i<n-1, i++)
if(x[i]>x[i+1])
{
a=x[i];
x[i]=x[i+1];
x[i+1]=a;
t==0;
}
}
for(i=0, i<=n, i++)
cout<<x[i]<< ;
getch();
}

Metoda selectiei
#include<iostrem.h>
#include<conio.h>
Int i, x[50], n, p, j, min
int main()
{
cout<<n=;
cin>>n;
for(i=1, i<=n, i++)
{
cout<<x[<<i<<]=;
cin>>x[i];
}
for(i=1, i<=n, i++)
{
min=x[i];
p=i;
for(j=i, j<=n, j++)
if(x[j]<min)
{
min=x[j];
p=j;
}
x[p]=x[i]
x[i]=min
}
for(i=1, i<=n, i++)
cout<<x[i]<< ;
getch();
}

Intrcalarea a doui vectori ordonati


#include<iostrem.h>
#include<conio.h>
Int x[50], y[50], z[100] n, m, i, j,k;
int main()
{
cout<<n=;
cin>>n;
cout<<m=;
cin>>m;
for(i=1, i<=n, i++)
{
cout<<x[<<i<<]=;
cin>>x[i];
}
for(j=1, j<=n, j++)
{
cout<<y[<<j<<]=;
cin>>y[j];
}
i=0; j=0; k=0;
while(i<n && j<m)
if(x[i]<[j])
{
z[k]=x[i];
i++; k++;
}
else
{
z[k]=y[j];
j++; k++;
}
If(i<n)
for(j=i, j<=n, j++)
{z[k]=x[j];
k++;}
if(j<m)
for(i=j, i<=m, i++)
{z[k]=y[j];
k++;}
for(k=0, k<n+m, k++)
cout<<z[k]<< ;
getch();
}

Metoda de cautare liniara


(intr-un vector ordonat)

#include<iostrem.h>
#include<conio.h>
Int x[100], n, i, a, p, u, k, m
int main()
{
cout<<n=;
cin>>n;
cout<<a=;
cin>>a;
for(i=1, i<=n, i++)
{
cout<<x[<<i<<]=;
cin>>x[i];
}
p=0; u=n-1; k=0;
while(k==0 && p<u)
{
m=(p+m)/2;
if(x[m]==a)
k=1;
else
if(x[m]>a)
u=m-1;
else
p=m+1;
}
if(k==0)
cout<<a<<nu esxista;
else
cout<<a<<se gaseste pe pozitia<<m;
getch();
}

Metoda de cautare secventiala


(intr-un vector neordonat)
for(i=0, i<=n, i++)
If(x[i]==a)
t=1;
if(t==0)
cout<<nu exista;
else
cout<<exista;
i=0
while(x[i]!=a && i<n)
{
i++
if(i<n)
cout<<nu exista
else
cout<<exista

__________________________________________
x[n]=a;
i=0;
while(x[i]!=a)
i++;
if(i==n)
cout<<nu exista
else
cout<<exista

You might also like