This C++ Program demonstrates the implementation of Sorted Array.
Here is source code of the C++ Program to demonstrate the implementation of Sorted Array. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Implement Sorted Array
*/
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
int array[100001] = {0}, value;
char ch = 'y';
while (ch == 'Y' || ch == 'y')
{
cout<<"Enter an integer to be inserted: ";
cin>>value;
array[value] = value;
cout<<"Do you want to insert more ( Y or N): ";
cin>>ch;
}
for(int i = 0; i < 100001; i++)
{
if (array[i] != 0)
cout<<array[i]<<" ";
}
cout<<endl;
return 0;
}
$ g++ sorted_array.cpp $ a.out Enter an integer to be inserted: 10 Do you want to insert more ( Y or N): Y Enter an integer to be inserted: 6 Do you want to insert more ( Y or N): Y Enter an integer to be inserted: 11 Do you want to insert more ( Y or N): Y Enter an integer to be inserted: 3 Do you want to insert more ( Y or N): Y Enter an integer to be inserted: 8 Do you want to insert more ( Y or N): Y Enter an integer to be inserted: 2 Do you want to insert more ( Y or N): Y Enter an integer to be inserted: 7 Do you want to insert more ( Y or N): Y Enter an integer to be inserted: 1 Do you want to insert more ( Y or N): N 1 2 3 6 7 8 10 11 ------------------ (program exited with code: 1) Press return to continue
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Check Programming Books
- Check C++ Books
- Apply for C++ Internship
- Check Computer Science Books
- Apply for Computer Science Internship