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
777dan777 [17]
3 years ago
11

Write a program in C++ to implement bubblesort using the swap function ?

Computers and Technology
1 answer:
marishachu [46]3 years ago
3 0

C++ program for implementation of Bubble sort  

#include <bits/stdc++.h>  

using namespace std;  

 void swap(int *x, int *y)  /*Defining Swap function of void return type*/

{  

  int temp = *x;  //Swaping the values  

   *x = *y;  

   *y = temp;  

}  

void bubbleSort(int array[], int n) /*Defining function to implement bubbleSort  */

{  

  int i, j;  

  for (i = 0; i < n-1; i++)      

      for (j = 0; j < n-i-1; j++)  /*The last i components are already in location  */

      if (array[j] > array[j+1])  

          swap(&array[j], &array[j+1]);  //Calling swap function

}  

int main()  //driver function

{  

   int array[] = {3, 16, 7, 2, 56, 67, 8}; //Input array  

   int n = sizeof(array)/sizeof(array[0]);  //Finding size of array

   bubbleSort(array, n); //Function calling  

   cout<<"Sorted array: \n";  

   for (int i = 0; i < n; i++)  //printing the sorted array

       cout << array[i] << " ";  

   cout << endl;  

 return 0;  

}  

<u>Output</u>

Sorted array:  

2 3 7 8 16 56 67

You might be interested in
A large retail company hires several new joiners and would like to incorporate Virtual Reality (VR) into their onboarding proces
Volgvan

 The best utilize VR for this purpose is a simulated experience interacting with customers.

<h3>What is Virtual reality (VR)?</h3>

Virtual Reality (VR) is known to be a kind of computer created environment that is made up of scenes and objects that seems to be real.

It is a type of reality that makes its  user feel they are inside their surroundings. This environment is said to be seen via device known as a Virtual Reality headset or helmet.

See options below

Which approach would best utilize VR for this purpose?

an animated video that covers compliance training

a 360-degree online tour of the retail store

an application that enables online contract signing

a simulated experience interacting with customers

Learn more about Virtual Reality (VR) from

brainly.com/question/26705841

4 0
2 years ago
Design and implement an algorithm that gets as input a list of k integer values N1, N2,..., Nk as well as a special value SUM. Y
satela [25.4K]

Answer:

Follows are the code to this question:

def FindPair(Values,SUM):#defining a method FindPair  

   found=False;#defining a boolean variable found

   for i in Values:#defining loop for check Value  

       for j in Values:#defining loop for check Value

           if (i+j ==SUM):#defining if block that check i+j=sum

               found=True;#assign value True in boolean variable

               x=i;#defining a variable x that holds i value

               y=j;#defining a variable x that holds j value

               break;#use break keyword

       if(found==True):#defining if block that checks found equal to True

           print("(",x,",",y,")");#print value

       else:#defining else block

           print("Sorry there is no such pair of values.");#print message

Values=[3,8,13,2,17,18,10];#defining a list and assign Values

SUM=20;#defining SUM variable

FindPair(Values,SUM);#calling a method FindPair

Output:

please find the attachment:

Explanation:

In the above python code a method, "FindPair" is defined, which accepts a "list and SUM" variable in its parameter, inside the method "found" a boolean variable is defined, that holds a value "false".

  • Inside the method, two for loop is defined, that holds list element value, and in if block, it checks its added value is equal to the SUM. If the condition is true, it changes the boolean variable value and defines the "x,y" variable, that holds its value.
  • In the next if the block, it checks the boolean variable value, if the condition is true, it will print the "x,y" value, otherwise, it will print a message.  

6 0
3 years ago
Using Turtle Graphics, write a program that will produce 2 Zs next to each other. It is irrelevant where these Zs appear and wha
LekaFEV [45]

Answer:

# import the  turtle library

from turtle import *

# create a turtle space

space = Screen()

# create a turtle object

z = Turtle()

 

# create a single Z

z.forward(50)

z.right(120)

z.forward(100)

z.left(120)

z.forward(50)

 

# adjust the turtle position

z.up()

z.left...

Explanation:

8 0
3 years ago
In a typical system design specification, the _____ section describes the constraints, or conditions, affecting a system, includ
Lapatulllka [165]

Answer:

The answer is "Option B".

Explanation:

The system environment includes all software external areas, which may vary from user to user. The System may be different, but it is part of the System environment, depending on the level of available memory. This environment is a part of the System development life cycle. and other options that are not correct which can be described as follows:

  • In option a, Time and cost estimates are part of the SDLC. It is a part where we calculate the overall cost and time for making any new software.
  • In option c, It is not a use in system environment it is reported.
  • In option d, System Components are a hardware device that by system environment for making a system environment but it does not include systems security that's why it is not correct.
6 0
3 years ago
Instructions
marta [7]

Answer:

Explanation:

5 0
3 years ago
Other questions:
  • What is the purpose of a scatter plot introduction to computer applications
    6·2 answers
  • Which keyboard feature is a form feed character?
    15·1 answer
  • PowerPoint is great for brainstorming and producing creative pieces because it
    13·2 answers
  • Wireless attacks avoid the access points to limit detection. <br> a. True <br> b. False
    9·1 answer
  • The domain name service (dns is a distributed database that allows users to communicate with each other computers by:
    7·1 answer
  • So i'm trying to figure out why this code wont run can anyone help me
    8·1 answer
  • Alguien me puede ayudar a arreglar mis auriculares que mi perro rompió en el conector
    5·1 answer
  • 13. By adding built-in writable memory to its cartridge, Nintendo’s _________________ was the first console game that gamers cou
    9·1 answer
  • I have this questions i need to make it in a report format pages of atleast 3 pages and maximum of 5 pages​
    7·1 answer
  • You are the CEO of a large tech company and have just received an angry email that looks like it came from one of your biggest c
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!