Problem Write a protected-mode, flat memory model program that computes the foll
ID: 3630430 • Letter: P
Question
Problem
Write a protected-mode, flat memory model program that computes the following.
1. Generate a set of 15 unique random integers in the range [19,79].
2. Display the original set with an annotation
3. Arrange the set in ascending order using a bubble sort algorithm as shown below
4. Display the sorted set with an annotation.
Notes
1.You may use any of the technology including functions from Irvine32. Directives, such as .IF, .WHILE, etc
.2. You must write global procedures that you call from main.
3. Part of the program will be graded on the basis of program style. I reserve the right to judge style as I deem fit for this assignment.
4. Your program will be graded using the Microsoft Visual C++ Express Edition environment.
Bubble sort algorithm
Please use the following algorithm to implement your sort.
Bubble-Sort (A)
for i 1 to length[A]
for j length[A] downto i + 1
if A[j] < A[j-1]
Swap A[j] A[j-1]
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int n[10];
cout<<"Enter 10 integer numbers:";
for (int i = 0;i<10;i++ )
cin>>n[i];
cout<<" After Sorting:";
_asm
{
mov edx,9
outerloop:
lea edi,n;
mov ecx,9;
Loop1: mov eax,[edi];
mov ebx,[edi+4];
cmp ebx,eax;
jae Loop2;
mov [edi + 4],eax;
mov [edi],ebx;
Loop2: add edi,4;
Loop Loop1;
sub edx, 1;
cmp edx, 0;
jnz outerloop;
}
for (int i = 0; i <= 10-1; i++)
cout<<n[i]<<" ";
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.