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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:37:29+00:00 2026-06-01T21:37:29+00:00

I have a problem with C++. I have a function which sorts the array,

  • 0

I have a problem with C++.

I have a function which sorts the array, but I don’t want to work on an original array. I want to send the array to the function by value not by reference. Please help me.

int bogoSort(int tab[], int n){
int iloscOperacjiDominujacych = 0;
    cout<<"rozpoczalem algorytm BogoSort"<<endl;

    srand (time(NULL));
    named (outer)
    while(true){
 //       cout<<"Zaczal sie while"<<endl;
        named (inner)
        for(int i = 0; i < n; i++){
            if(i == n-1){
                break (outer);
            }
            if (tab[i] > tab[i+1]){
                break (inner);
            }
        }
        for(int i = n-1; i > 0; i--){
            iloscOperacjiDominujacych++;
            //operacja dominujaca to zamiana dwoch elementow w tablicy, wykonuje sie ZAWSZE najwiecej razy i jest najbardziej zlozona
            int swapPostition =  rand() % (i+1); //wylosowanie liczby miedzy <0;i> nalezacej do calkowitych
            int temp = tab[i];
            tab[i] = tab[swapPostition];
            tab[swapPostition] = temp;
        }
    }
//    cout<<"Wykonal sie while"<<endl;
    show(tab,n);
    return iloscOperacjiDominujacych;
}
  • 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-01T21:37:31+00:00Added an answer on June 1, 2026 at 9:37 pm

    There is no way to pass an array by value in C++. If you don’t want to modify the original array, then you either have to make a separate copy yourself and manipulate the copy, or use std::vector or std::array (if you have C++11) and pass and return it by value (because you can copy std::vector or array).

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

Sidebar

Related Questions

I have an algorithm problem that I came across at work but have not
I have got a problem with calling a global function, which takes a pointer
I have an interesting problem, which is a function that returns a Dictionary<String,HashSet<String>> .
I have problems with following code: http://lisper.ru/apps/format/96 The problem is in normalize function, which
I have a problem with Jquery function getJSON, the action url does not trigger
I have problem with fancybox. I want to write a function that will run
I want to have a SelectAll function which takes in a few arguments (class,
I have a problem. I have getAllJobsControllerUrl() function which return url with specific parameters:
I have priority queue which sorts elements by some value(lets name it rating). I
I have the following loop which is giving me problems $(#divResults).append('<table>'); $.each( results.d, function(

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.