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 7545973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:04:42+00:00 2026-05-30T09:04:42+00:00

I am trying to write my own bubble sort algorithm as an exercise. I

  • 0

I am trying to write my own bubble sort algorithm as an exercise. I do not understand the two error messages. Can anyone point out the problem with my code?

// Bubble sort algorithm
#include <iostream>
#include <iomanip>
using namespace std;

void bubbleSort(int array[], int arraySize); // bubbleSort prototype

int main(void)
{
        const int arraySize = 10;
        int array[arraySize] = {2,3,6,5,7,8,9,3,7,4};

        cout << "Unsorted: ";
        for(int i = 0; i < arraySize; ++i)
                cout << setw(5) << array[i];

        cout << "Sorted: " << bubbleSort(array, arraySize);
}

void bubbleSort(int array[], int arraySize)
{
        const int max = arraySize;
        int swap = 0;

        for(int i = 0; i < max; ++i)
        {
                if(array[i] > array[i + 1])
                {
                        swap = array[i + 1];
                        array[i + 1] = array[i];
                        array[i] = swap;
                }
                else
                        break;
        }
}
  • 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-30T09:04:44+00:00Added an answer on May 30, 2026 at 9:04 am

    I see that you are using

    using namespace std;
    

    So when you type

    array[i] = swap;
    

    The compiler cannot disambiguate whether you are referring to the std::swap function or your int swap variable. In fact it looks like it assumed you were referring to the function and tried to somehow convert it to type int. Try renaming your variable to something else.

    In general, try to stay away from using directives, to avoid name collisions like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write my own JVM. Can you point me to some
I'm trying to write my own function like with no luck. ...is not a
I'm trying to write my own code for a 'friends-of-friends' algorithm. This algorithm acts
I'm trying to write my own toy My Toy Language -> MSIL compiler in
I am trying to write our own RIA services provider to expose data from
I have been trying to write my own diff3 wrap script for SVN and
I have been trying to write a small app with its own option windows.
(Edit: randrange is just random.randrange, I didn't write my own RNG) I'm trying to
I trying to write my own Event Aggregation class and i go some articles
I'm trying to write my own function to block events. Here is what I

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.