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

Program Sorting & Searching

The document describes two algorithms: 1) Bubble sort, which sorts an array of integers by repeatedly swapping adjacent elements that are in the wrong order. 2) Sequential search, which searches an array of integers for a target value by checking each element in order until a match is found or all elements are checked. It provides C++ code implementations of these algorithms to sort an sample integer array and search it for a given value.

Uploaded by

akbar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Program Sorting & Searching

The document describes two algorithms: 1) Bubble sort, which sorts an array of integers by repeatedly swapping adjacent elements that are in the wrong order. 2) Sequential search, which searches an array of integers for a target value by checking each element in order until a match is found or all elements are checked. It provides C++ code implementations of these algorithms to sort an sample integer array and search it for a given value.

Uploaded by

akbar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Program Sorting (Bubble Sort)

#include <iostream.h>

#include <iomanip.h>

#include <conio.h>

int main ()

clrscr();

int data [4]={5,34,32,25};

int temp;

cout<<"Data Sebelum Diurutkan : \n";

for (int d=0; d<4; d++)

cout<<setw(3)<<data[d];

cout<<"\n\n";

for(int i=0; i<4; i++)

for(int j=0; j<3; j++)

if (data[j] > data[j+1])

temp=data[j];

data[j]=data[j+1];

data[j+1]=temp;

cout<<"Data Setelah Diurutkan : \n";


for(int k=0; k<4; k++)

cout<<setw(3)<<data[k]<<endl<<endl;

getch();

Program Searching (Sequential Search)

#include <iostream.h>

#include <iomanip.h>

#include <conio.h>

int main ()

clrscr();

int data [4]={5,34,32,25};

int d,cari,ketemu;

cout<<"Data Di Array : \n";

for ( d=0; d<4; d++)

cout<<setw(3)<<data[d];

cout<<"\n\n";

cout<<"Data Yang dicari:";

cin>>cari;
d=0;

while (d < 4 && ketemu !=1)

if (data[d] == cari)

ketemu=1;

else

d++;

ketemu=0;

}}

if (ketemu == 1)

cout<<"Data:"<<cari<<"Ketemu di index ke :"<<d;

else

cout<<"Data Tidak ketemu";

getch();

You might also like