C++ Program to Perform Searching Based on Locality of Reference

My Projects
Change Password
My Profile
Logout
Undo
Redo
Cut
Copy
Paste
Delete
Select All
Find
Find and Replace
Editor Theme
Crimson
Eclipse
Github
Solarized
Cobalt
krTheme
Monokai
Terminal
Textmate
Twilight
Vibrant Ink
Font Size
8px
9px
10px
11px
12px
13px
14px
15px
16px
17px
18px
20px
22px
24px
Tab Size
1
2
3
4
5
6
7
8
Show Invisible
Hide Invisible
Show Line Numbers
Hide Line Numbers
Ace Editor (Default)
Vim Editor
Emacs Editor
Open New Project
Save Project
Save As New Project
Share Project
Search Project
#include<iostream> using namespace std; // A function to perform linear search. // this method makes a linear search. int find(int *intarray, int n, int item) { int i; int comparisons = 0; // navigate through all items for(i = 0;i<n;i++) { // count the comparisons made comparisons++; // if item found, break the loop if(item == intarray[i]) { cout<<"element found at:"<<i<<endl; break; } // If index reaches to the end then the item is not there. if(i == n-1) { cout<<"\nThe element not found."; return -1; } } printf("Total comparisons made: %d", comparisons); // Shift each element before matched item. for(int j = i; j > 0; j--) intarray[j] = intarray[j-1]; // Put the recently searched item at the beginning of the data array. intarray[0] = item; return 0; } int main() { int intarray[20]={1,2,3,4,6,7,9,11,12,14,15,16,26,19,33,34,43,45,55,66}; int i,n; char ch; // print initial data array. cout<<"\nThe array is: "; for(i = 0; i < 20;i++) cout<<intarray[i]<<" "; up: cout<<"\nEnter the Element to be searched: "; cin>>n; // Print the updated data array. if(find(intarray,20, n) != -1) { cout<<"\nThe array after searching is: "; for(i = 0; i <20;i++) cout<<intarray[i]<<" "; } cout<<"\n\nWant to search more.......yes/no(y/n)?"; cin>>ch; if(ch == 'y' || ch == 'Y') goto up; return 0; }

C++ Program to Perform Searching Based on Locality of Reference (GNU GCC v7.1.1)

C++ Program to Perform Searching Based on Locality of Reference (GNU GCC v7.1.1) helps you to Edit, Run and Share your C++ Code directly from your browser. This development environment provides you version GNU GCC v7.1.1.

How to give program Input?

The latest version of Coding Ground allows to provide program input at run time from the termnial window exactly the same way as you run your program at your own computer. So simply run a program and provide your program input (if any) from the terminal window available in the right side.

Keyboard Shortcuts

ShortcutDescription
⌘ + EnterRun the program
⌘ + SSave Project (Login Required)
⇧ + ⌘ + SSave As Project
⌘ + PNew Project
⌘ + GShare Project
⌘ + ZUndo Editing
⌘ + YRedo Editing
⌘ + ASelect All Text
⌘ + XCut Selected Text
⌘ + CCopy Selected Text
⌘ + VPaste Copied Text
⌘ + FSearch Text
⌘ + ⌥ + FReplace Text
ShortcutDescription
Ctrl + EnterRun the program
Ctrl + SSave Project
Shift + Ctrl + SSave As Project
Ctrl + GShare Project
Ctrl + ZUndo Editing
Ctrl + YRedo Editing
Ctrl + ASelect All Text
Ctrl + XCut Selected Text
Ctrl + CCopy Selected Text
Ctrl + VPaste Copied Text
Ctrl + FSearch Text
Ctrl + HReplace Text

Save C++ Project

You can save your C++ Project with us so that you can access this project later on. To save a project you will need to create a login Id with us. So before you save a project, please create a login Id using a link given at the top right corner of this page.

Share C++ Project

You can use this feature to share your C++ Code with your teachers, classmates and colleagues. Just click Share Button and it will create a short link, which can be shared through Email, WhatsApp or even through Social Media. A shared link will be deleted if it has been passive for almost 3 months.

 Execute |  Beautify | Share