Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6610567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:51:26+00:00 2026-05-25T19:51:26+00:00

How do I make a binary search replace an element of an array of

  • 0

How do I make a binary search replace an element of an array of strings with another element of an array of strings? This is the final part of my program and I don’t get it…I know with char’s you use strcpy, or .replace, etc.

I have a struct that has an “orginalWord” and a “replacementWord”, then a string array of “inputword”‘s, it takes the inputword, finds it within the struct array (comparing to the orginalWord), and once found (Which it does find it…that part works, it finds the correct element number, so I know the searching is correct) replaces the “inputword” with the “replacementword”. I just can’t make it replace the element within the “inputword” with the “reaplcementWord” it finds. Help please!! I’ll post the Binarysearch function seperate from the rest of my code for easy of reading. I know this should be simple, but I can’t remember for the life of me.

Example: So…searchitem is inputword[20] = “Like”. Sruct Array… encryption[50].OrginalWord = “Like”. Match found…encryption[50].ReplacementWord = “Ducks”. I would like to put “Ducks” into inputword[20]. How would I do this using the BinarySearch?

//Function call within main:
for(number=0; number < plaincount; number++)
        { BinarySearch(encryption, count, inputword[number]);
         } 

int BinarySearch (StringPair correctword[], int size, string searchitem)
{   
    int middle =0, start = 0, last = size-1;
    bool found = false;
    int position = -1;
    while (!found && start <= last)
    { 
        middle = (start + last)/2; // Midpoint // Was a breakpoint here, why?
        if(correctword[middle].orginalWord == searchitem)
        {               
            position = middle;
            cout << "Replacing word: " << searchitem << " With: " << position << endl;

            searchitem.swap(correctword[position].replacementWord);

            found = true;
            return position; // Return new value for inputword array?
        }
        else if (correctword[middle].orginalWord < searchitem)
            { start = middle+1; }
        else last = middle-1;
    }
    cout << "Misspelled word found: " << searchitem << endl;
    return false;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:51:27+00:00Added an answer on May 25, 2026 at 7:51 pm

    If searchitem is going to be modified, you need to pass it by reference:

    int BinarySearch (StringPair correctword[], int size, string &searchitem)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a string binary search program. Trouble is I don't remember
I'm trying to set up a Binary search program that uses strings instead of
This is related to primary database indexing mechanism (sparse indexing). Binary search can be
In Scheme, I can use define-struct to make a binary search tree, but how
Im a little confused. Im wondering if an array based Binary Search tree is
i m trying to make a program to convert a number into it's binary.
I'm working on a project where I have to make a binary search tree
I'm trying to make a list of all items in a binary search tree.
The Binary Tree here is may not necessarily be a Binary Search Tree. The
We always see operations on a (binary search) tree has O(logn) worst case running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.