• Login
    • Search
    • Categories
    • Recent
    • Tags
    • Users
    • Groups
    • Rules
    • Help

    Do more on the web, with a fast and secure browser!

    Download Opera browser with:

    • built-in ad blocker
    • battery saver
    • free VPN
    Download Opera

    Aria provides links in the block where it gives the actual code

    Bugs
    2
    2
    783
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • soumyanil22
      soumyanil22 last edited by leocg
      #include <iostream>
      #include <vector>
      
      using namespace std;
      
      int binarySearch(vector<int> [arr](https://www.google.com/search?q=arr), int [l](https://www.google.com/search?q=l), int [r](https://www.google.com/search?q=r), int [x](https://www.google.com/search?q=x)) {
         if ([r](https://www.google.com/search?q=r) >= [l](https://www.google.com/search?q=l)) {
            int mid = [l](https://www.google.com/search?q=l) + ([r](https://www.google.com/search?q=r) - [l](https://www.google.com/search?q=l)) / 2;
      
            if ([arr](https://www.google.com/search?q=arr)[mid] == [x](https://www.google.com/search?q=x))
               return mid;
      
            if ([arr](https://www.google.com/search?q=arr)[mid] > [x](https://www.google.com/search?q=x))
               return binarySearch([arr](https://www.google.com/search?q=arr), [l](https://www.google.com/search?q=l), mid - 1, [x](https://www.google.com/search?q=x));
      
            return binarySearch([arr](https://www.google.com/search?q=arr), mid + 1, [r](https://www.google.com/search?q=r), [x](https://www.google.com/search?q=x));
         }
      
         return -1;
      }
      
      int main() {
         vector<int> [arr](https://www.google.com/search?q=arr) = { 2, 3, 4, 10, 40 };
         int [n](https://www.google.com/search?q=n) = [arr](https://www.google.com/search?q=arr).size();
         int [x](https://www.google.com/search?q=x) = 10;
      
         int result = binarySearch([arr](https://www.google.com/search?q=arr), 0, [n](https://www.google.com/search?q=n) - 1, [x](https://www.google.com/search?q=x));
      
         if (result == -1)
            cout << "Element is not present in array" << endl;
         else
            cout << "Element is present at index " << result << endl;
      
         return 0;
      }
      
      

      this was the reponse I got when I asked it to code binary search in c++.

      Reply Quote 2
        1 Reply Last reply
      • stolowski
        stolowski last edited by

        Yes, I can confirm this, I'm seeing this issue a lot in code snippets offered by Aria (I've used it for C++ only).

        Reply Quote 1
          1 Reply Last reply
        • First post
          Last post

        Computer browsers

        • Opera for Windows
        • Opera for Mac
        • Opera for Linux
        • Opera beta version
        • Opera USB

        Mobile browsers

        • Opera for Android
        • Opera Mini
        • Opera Touch
        • Opera for basic phones

        • Add-ons
        • Opera account
        • Wallpapers
        • Opera Ads

        • Help & support
        • Opera blogs
        • Opera forums
        • Dev.Opera

        • Security
        • Privacy
        • Cookies Policy
        • EULA
        • Terms of Service

        • About Opera
        • Press info
        • Jobs
        • Investors
        • Become a partner
        • Contact us

        Follow Opera

        • Opera - Facebook
        • Opera - Twitter
        • Opera - YouTube
        • Opera - LinkedIn
        • Opera - Instagram

        © Opera Software 1995-