Bachelor of Technology in Information Technology



Download 0,65 Mb.
bet10/14
Sana20.03.2022
Hajmi0,65 Mb.
#502184
1   ...   6   7   8   9   10   11   12   13   14
Bog'liq
PSP Lab Manual

Binary Search ALGORITHM:


STEP 1: Start
STEP 2: Declare the variables i, first, last, middle, n, search, array[100]
STEP 3: Input the number of ‘n’
STEP 4: // Input the values in an array array[i] for(i=0; iDisplay the values ‘array[i]
STEP 5: Input the value of ‘search’ you want to search in an array a[i] first = 0;
last = n - 1;
middle = (first+last)/2; STEP 6: while (first <= last)
if(array[middle] < search) first = middle + 1;
else if (array[middle] == search) display value found at location break
else
last = middle - 1;
middle = (first + last)/2; if(first > last)
display value not found STEP 7: Stop


SOURCE CODE:


#include #include void main()


{
int i, first, last, middle, n, search, array[100]; printf("Enter number of elements\n"); scanf("%d",&n);


printf("Enter %d integers\n", n); for(i = 0; i < n; i++) scanf("%d",&array[i]); printf("Enter value to find\n"); scanf("%d", &search);
first = 0; last = n - 1;
middle = (first+last)/2; while (first <= last)
{

if(array[middle] < search) first = middle + 1;


else if (array[middle] == search)



{
}
else
printf("%d found at location %d.\n", search, middle+1); break;

last = middle - 1;



middle = (first + last)/2;


}
if(first > last)
printf("Not found! %d isn't present in the list.\n", search); getch();
}



------------------------------*-----------OUTPUT----------------*------------------------


  1. Bubble Sort ALGORITHM:


STEP 1: Start
STEP 2: Declare the variables c, d, n, array[10], swap STEP 3: Input the number of elements into array ‘n’ STEP 4: Input the values in an array, a[i]

for(c=0; c
STEP 5: Sort the array elements
for (c = 0 ; c < n - 1; c++) //No. of passes
for (d = 0 ; d < n - c - 1; d++) //Inner iterations comparision if (array[d] > array[d+1]) /* For decreasing order use < */

swap = array[d]; array[d] = array[d+1]; array[d+1] = swap;


STEP 6: Display the sorted array for(c = 0; c < n; c++)
display sorted array elements STEP 7: Stop



Download 0,65 Mb.

Do'stlaringiz bilan baham:
1   ...   6   7   8   9   10   11   12   13   14




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish