Tech Unleashed

Wohoo!! We're on YouTube

Friday, 3 November 2023

C++ : Lecture 3: Linear Search Algorithm : C++ Confusion Buster !

 C++ Confusion Buster: Your Easy Guide to C++ !


Linear Search Algorithm code [C++] :


// Shyam Sunder Kanth
// Insta : still_23.6_8
// Linear Search 

#include<iostream>

using namespace std;

int linearSearch(int arr[], int target, int len){
    for(int i=0;i<len;i++){
        if(arr[i] == target){
            return i;
        }
    }
    return -1;
}

int main()
{
    int arr[5] = {5,2,7,6,9};
    int target = 6;
    int len = sizeof(arr)/sizeof(arr[0]);
    
    int res = linearSearch(arr,target,len);
    if(res == -1){
        cout<<"Element Not found"<<endl;
    }else{
        cout<<target<<" is found at position "<<res+1<<endl;
    }

    return 0;
}

Hey, thanks for watching our video about Linear Search algorithm ! In this video we’ll walk you through:

- Concept

- How It works ?

- Implementatiom

- Code


All codes are available at my GitHub account, check them out here:

https://github.com/shyamkanth/Placements


Check out other videos from DS Revealed playlist: https://www.youtube.com/playlist?list=PLNXqJgOsTCZOB60T9HDhMf_o8RXbNWgqS


Check out our channel here: https://www.youtube.com/@DevelopersByte


Find us at: https://shyamkanth.github.io/


Timestamps:

0:00 Intro

0:28 Concept

1:55 How it works?

5:18 Approach

20:48 Code

25:18 Output


About our channel:

Our channel is about Revealing the secrets of Data Structure. We cover lots of cool stuff such as Codes, Concepts and Implementations.

Check out our channel here: https://www.youtube.com/@DevelopersByte

Don’t forget to subscribe!


Follow me on social media:

Get updates or reach out to Get updates on our Social Media Profiles!

GitHub: https://github.com/shyamkanth/

Instagram: https://instagram.com/still_23.6_8

Instagram personal: https://instagram.com/itz_sammmii

No comments:

Post a Comment