1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kolbaska11 [484]
3 years ago
15

Write a function in Java that takes in the int[] array, sorts it using bubble sort, then returns back the sorted array. Examples

:
Computers and Technology
1 answer:
Vlad1618 [11]3 years ago
6 0

Answer:

static int [] bubbleSort(int[] arr) {  

       int n = arr.length;  

       int temp = 0;  

        for(int i=0; i < n; i++){  

                for(int j=1; j < (n-i); j++){  

                         if(arr[j-1] > arr[j]){      

                                temp = arr[j-1];  

                                arr[j-1] = arr[j];  

                                arr[j] = temp;  

                       }      

                }  

        }

        return arr;  

   }  

Explanation:

Above function is written in java language in which it takes integer array then sorts it using bubble sort and return back the array. The function has return type int[] which is necessary for returning array of type integer. The variable n contains the size of array which is calculated through  array's length method which is built in. Above function sorts array in descending order if you want to sort it in ascending order just change the condition of in if branch from <em>"</em><em>if(</em><em>arr[j-1] > arr[j]</em><em>)</em><em>"</em> to <em>"</em><em>if(</em><em>arr[j-1] < arr[j]</em><em>)</em><em>"</em> means replace > sign with < sign .

You might be interested in
Recognition systems trained for individual users, such as Dragon NaturallySpeaking, are quite good at processing both voice comm
zhenek [66]
I think it’s True I’m not for sure


-TwoTime-
7 0
4 years ago
The dark side of communication involves interactions that are: Challenging; Difficult; Distressing; All of the above
Romashka [77]
When we engage in actions that are designed to sustain or preserve a relationship what is it called
6 0
4 years ago
convert the following c code to mips. assume the address of base array is associated with $s0, n is associated with $s1, positio
Brums [2.3K]

Answer:

Explanation:

hello we will follow a step by step process for this code, i hope you find it easy.

Mips Equivalent code:

  sw      $0,0($fp)

.L7:

       lw      $2,12($fp)

       addiu   $2,$2,-1

       lw      $3,0($fp)

       slt     $2,$3,$2

       beq     $2,$0,.L2

       nop

       lw      $2,0($fp)

       sw      $2,8($fp)

       lw      $2,0($fp)

       addiu   $2,$2,1

       sw      $2,4($fp)

.L5:

       lw      $3,4($fp)

       lw      $2,12($fp)

       slt     $2,$3,$2

       beq     $2,$0,.L3

       nop

       lw      $2,8($fp)

       dsll    $2,$2,2

       daddu   $2,$fp,$2

       lw      $3,24($2)

       lw      $2,4($fp)

       dsll    $2,$2,2

       daddu   $2,$fp,$2

       lw      $2,24($2)

       slt     $2,$2,$3

       beq     $2,$0,.L4

       nop

       lw      $2,4($fp)

       sw      $2,8($fp)

.L4:

       lw      $2,4($fp)

       addiu   $2,$2,1

       sw      $2,4($fp)

       b       .L5

       nop

.L3:

       lw      $3,8($fp)

       lw      $2,0($fp)

       beq     $3,$2,.L6

       nop

       lw      $2,0($fp)

       dsll    $2,$2,2

       daddu   $2,$fp,$2

       lw      $2,24($2)

       sw      $2,16($fp)

       lw      $2,8($fp)

       dsll    $2,$2,2

       daddu   $2,$fp,$2

       lw      $3,24($2)

       lw      $2,0($fp)

       dsll    $2,$2,2

       daddu   $2,$fp,$2

       sw      $3,24($2)

       lw      $2,8($fp)

       dsll    $2,$2,2

       daddu   $2,$fp,$2

       lw      $3,16($fp)

       sw      $3,24($2)

.L6:

    lw      $2,0($fp)

       addiu   $2,$2,1

       sw      $2,0($fp)

       b       .L7

        nop

cheers  i hope this helps

7 0
3 years ago
What aspects of your life are most influenced by media and technology​
Anastasy [175]

Answer:

Everyday life

Explanation:

Television

office work (computers )

Music

video games

ware house work uses technology

work from home jobs use technology

cellular towers

5 0
3 years ago
About C header files of C programming
Neko [114]

Answer:

A header file is a file with an extension. Which contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that come with your compiler.

3 0
3 years ago
Other questions:
  • on average, someone with a bachelor’s degree is estimated to earn _______ times more than someone with a high school diploma
    13·1 answer
  • How does a hard drive work
    6·2 answers
  • Bruno took the computer that he uses at work, and Pauline sits on the beach with her laptop computer, which she connects to the
    13·1 answer
  • What does coding mean​
    10·2 answers
  • PLEASE HELP ILL MARK BRAINLIEST!!!
    10·1 answer
  • How can ICT be a tool in connecting all stakeholders in your community?
    5·1 answer
  • Name and define (or list the set that defines) three of the four common data types in programming.
    15·1 answer
  • Which cpu type would most likely be found in a smartphone?.
    10·1 answer
  • Write a function called middle(string str) that returns a string containing the middle character in str if the length of str is
    10·1 answer
  • Data will zip through a 5G network much faster than through a 4G network because of the 10-fold difference in _____.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!