C++ Array Searching and Sorting

Verified

Added on  2019/09/16

|2
|251
|292
Practical Assignment
AI Summary
This document presents a practical assignment solution in C++ focusing on array manipulation, searching, and sorting algorithms. The assignment is divided into two parts: Part A involves filling an array with random integers, printing the array, and implementing a sequential search. Part B focuses on implementing bubble sort, binary search, and selection sort algorithms. The provided C++ code includes a `seqSearchItem` function for sequential search and a `main` function for testing. The code demonstrates how to search for an item in an array and provides a basic framework for implementing the other required functions.
Document Page
By using C++
We use arrays to implement lists and perform different searching and sorting
algorithms on those lists.
Your program should include one function for each of the operations, as well as a
main function for testing each.
Part A:
1.Fill Array _ fill an array list with random integers
2.Print Array-
3.segSearch-
part B:
1. BubbleSort
2. BinarySearch
3. SelectionSort
N.B you can edit and follow this code
// squential searching and sorting C++programe
#include <iostream>
using namespace std;
int seqSearchItem (int list [], int length, int item)
{
int loc;
bool found = false;
for (loc = 0; loc < length; loc++)
{
if (list [loc] == item)
{
found = true;
break;
}
}
if (found)
return loc;
else
return -1;
}
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
int main()
{
int intlist[]= {2,16,34,45,53};
int pos;
pos= seqSearchItem(intlist,10,45);
if (pos!=-1)
cout<<" line5:"<<45<<"found at position"<<pos<<endl;
print(intlist,45);
else
cout<<"line7:"<<45<<"is not in inlist"<<endl;
system("pause");
return 0;
}
chevron_up_icon
1 out of 2
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]