Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first commit #17

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Arrays-algos/reversearrayalgo2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
void reversearray2(int arr[],int size)
{

int rev[size];
int j=0;
for(int i=size-1;i>=0;i++)
{
rev[j]=arr[i];
j++;
}

return rev;

}
Binary file added search-with-noob/a.exe
Binary file not shown.
Binary file added search-with-noob/a.out
Binary file not shown.
18 changes: 15 additions & 3 deletions search-with-noob/binary_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,25 @@ int binary_search(int array[], int search, int lower, int upper)
//Since the Binary Search needs a sorted array but we have an unsorted array so it needs to be sorted first.
//You can use any sorting method as per your convenience.

int sort(int arr[],int search)
int sort(int arr[],int search, int size)
{

for (int step = 0; step < size - 1; ++step)
{
for (int i = 0; i < size - step - 1; ++i)
{
if (arr[i] > arr[i + 1])
{
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
}

// You have to sort the array and call the binary function and return the result you get from that function to the main.

int result = binary_search(sorted_array_name, search_element, initial_lower_value, initial_upper value );
int result = binary_search(arr, search, 0, size-1 );
return result;
}

Expand All @@ -41,7 +53,7 @@ int main()
cout<<"Enter search element"<<endl;
cin>>search;
int size = sizeof(array) / sizeof(array[0]);
int result = sort(array, search);
int result = sort(array, search,size);
if (result == -1)
cout<<"Element not found"<<endl;
else
Expand Down
6 changes: 5 additions & 1 deletion search-with-noob/linear_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ int main()

int search_element;
//Take the input of the element to be searched by the user.
scanf("%d",&search_element);


int result = linear_search(arr,size,search_element);

//If the result is -1 then print that the element is not present in the array.
if(result==-1)
printf("element not found\n");
//If the result is any value but -1 then print the element is found on that index.

else
printf("element found at index %d",result);
return 0;

}