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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:28:51+00:00 2026-06-01T04:28:51+00:00

I have to write a swap function for my bubble sort That’s what I’ve

  • 0

I have to write a swap function for my bubble sort
That’s what I’ve got:

void swap(int arr[], int size, int i, int j)
{
    int temp = *(arr+i);
    *(arr + i) = *(arr+j);
    *(arr+j) = temp;
}

When I’m trying to run I get the following errors:

warning C4013: ‘swap’ undefined; assuming extern returning int
error C2371: ‘swap’ : redefinition; different basic types

When I do change the function to the type of int, it does work, any idea why?

I don’t need a prototype because it’s before the main function… do I?

Here’s the whole code:

//BubbleSort

    void bubbleSort(int arr[], int size)
    {
        int i,j;
        for(i=0; i < size; i++)
        {
            for(j=i+1; j < size; j++)
            {
                if(*(arr+i) > *(arr+j))
                {
                     /*temp = *(arr+i);
                    *(arr + i) = *(arr + j);
                    *(arr + j) = temp;*/
                    swap(arr,i,j);
                }
            }
        }
    }
    void swap(int arr[], int i, int j)
    {
        int temp = *(arr+i);
        *(arr + i) = *(arr+j);
        *(arr+j) = temp;
    }
    void main()
    {
        int i, arr[] = {8,0,6,-22,9};
        bubbleSort(arr, sizeof(arr)/sizeof(int));
        for(i=0; i < sizeof(arr)/sizeof(int); i++)
        {
            printf("%d, ",*(arr+i));
        }
        printf("\n");
    }
  • 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-06-01T04:28:52+00:00Added an answer on June 1, 2026 at 4:28 am

    Inside bubbleSort() you call a function named swap() but, at that point in the code, there is no function named swap() either defined or declared.

    Solution 1: move the defintion of swap() to before the definition of bubbleSort()
    Solution 2: specify the prototype of swap() before defining bubbleSort()

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

Sidebar

Related Questions

Write a function called swap which has a prototype of void swap (int&, int&);
I found that I have to perform a swap in python and I write
Hey all, I'm trying to write a sort function but am having trouble figuring
I am currently trying to write a program that alphabetizes strings. I have one
I'm trying to write a function to swap 2 elements in a 2D array:
I am trying to check if I have write access to a specific key
I'm writing a simple web app in PHP that needs to have write access
I have to write a Matlab script that does this: The input is 2
I want to discuss my problem clearly. I have a function to Swap value
I have a file format I'm trying to write to using C#. The format

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.