Davenport University Bubble Sort in C# with Visual Studio Using Arrays Project Bubble Sort
1. Implement a bubble sort in C# with Visual Studio using arrays. The algorithm for the bubble sort is shown in listing 1.
2. The bubble sort should sort an array of randomly assigned integers.
3. Sort a random list of elements of 100, 1,000, 10,000, 25,000, 50,000, 100,000, 250,000, 500,000, 750,000, and 1,000,000 elements, respectively and the time it takes (in milliseconds) to complete each sorting operation.
4. Graph the results in Excel using a single graph.
5. Repeat steps 3 and 4 above, but instead of using the Bubble Sort algorithm, use the language supplied sort method to sort the arrays. Graph your results using a second Excel graph.
6. Complete Programming Assignments require a Design & Testing Document CSCI312 – Searching and Sorting
Bubble Sort
1. Implement a bubble sort in C++, Java, C#, or VB.NET using arrays. The algorithm for the
bubble sort is shown in listing 1.
2. The bubble sort should sort an array of randomly assigned integers.
3. Sort a random list of elements of 100, 1,000, 10,000, 25,000, 50,000, 100,000, 250,000,
500,000, 750,000, and 1,000,000 elements, respectively and the time it takes (in milliseconds) to
complete each sorting operation.
4. Graph the results in Excel using a single graph.
procedure bubbleSort( A : list of sortable items )
n = length(A)
repeat
swapped = false
for i = 1 to n-1 inclusive do
if A[i-1] > A[i] then
swap(A[i-1], A[i])
swapped = true
end if
end for
n = n – 1
until not swapped
end procedure
Listing 1
5. Repeat steps 3 and 4 above, but instead of using the Bubble Sort algorithm, use the language
supplied sort method to sort the arrays. Graph your results using a second Excel graph.
NOTE: C++ programmers, please review the programmer’s note on the following page for
important details regarding allocating memory for large arrays.
When you are finished, upload your completed graph(s) (as an Excel document) and your
source code for your project to Blackboard. No testing or design document is required for this
lab assignment.
C++ Programmer’s Note
Large arrays must be dynamically allocated using the new operator (and conversely, must be
deallocated using the delete operator. Attempting to make a large array using the automatic
memory allocation will fail.
int a[500000];
// FAIL – Not enough memory on the heap…
// Workaround is to manually allocate memory
int *list = new int[500000];
// TO DO:
// Manually allocate an array
work with the array here
delete [] list;
// free memory manually allocated
list = NULL;
// set to NULL to prevent accidental use after freed
Time Calculations
C#
DateTime start = DateTime.Now;
DateTime end;
// TO DO:
Insert code to time here…
end = DateTime.Now;
TimeSpan ts = end.Subtract(start);
Console.WriteLine(“Duration = {0} ms”, ts.TotalMilliseconds);
Java
long start = System.currentTimeMillis();
long end = 0;
long total = 0;
// TO DO:
Insert code to time here…
end = System.currentTimeMillis();
total = end – start;
String s = String.format(“Duration = %d ms”, total );
System.out.println(s);
C++
SYSTEMTIME sysTimeStart, sysTimeEnd;
// include to use the time functions
ZeroMemory(&sysTimeStart, sizeof(SYSTEMTIME));
ZeroMemory(&sysTimeEnd, sizeof(SYSTEMTIME));
GetSystemTime(&sysTimeStart);
// TO DO:
Insert code to time here…
GetSystemTime(&sysTimeEnd);
long start = (sysTimeStart.wHour * 3600000) + (sysTimeStart.wMinute * 60000) +
(sysTimeStart.wSecond * 1000) + sysTimeStart.wMilliseconds;
long end = (sysTimeEnd.wHour * 3600000) + (sysTimeEnd.wMinute * 60000) +
(sysTimeEnd.wSecond * 1000) + sysTimeEnd.wMilliseconds;
long total = end – start ;
printf(“Duration = %i ms”, total);
VB.NET
Dim startTime As DateTime = DateTime.Now
Dim endTime As DateTime
‘ TO DO:
Insert code to time here…
endTime = DateTime.Now
Dim ts As TimeSpan = endTime.Subtract(startTime)
Console.WriteLine(“Duration = {0} ms”, ts.TotalMilliseconds)
Random Numbers
C#
Random rand = new Random();
int n = rand.Next(1, 101);
// initialize the random number generator.
// n is between 1 and 100
Java
Random rand = new Random();
int n = rand.nextInt(101) + 1;
// initialize the random number generator.
// import java.util.Random
// n is between 1 and 100
C++
srand ( time(NULL) );
int n = rand() % 100 + 1;
// initialize the random number generator.
// n is between 1 and 100
VB.Net
Dim rand As Random = New Random()
Dim n As Integer = rand.Next(101) + 1
include
// initialize the random number generator.
// n is between 1 and 100
Sorting
C#
int[] list = { 6, 4, 8, 7, 6, 9, 2, 1, -1, 5 };
Array.Sort(list);
Java
int[] list = { 6, 4, 8, 7, 6, 9, 2, 1, -1, 5 };
// import java.util.Arrays
Arrays.sort(list);
C++
// Sample compare function
int compare (const void *a, const void *b)
{
return ( *(int*)a – *(int*)b );
}
// Sample sorting code
int list[] = { 6, 4, 8, 7, 6, 9, 2, 1, -1, 5 };
const int SIZE = 10;
qsort(list, SIZE, sizeof(int), compare);
VB.NET
Dim list() As Integer = {6, 4, 8, 7, 6, 9, 2, 1, -1, 5}
Array.Sort(list)
// include
Programming Assignment Design and Testing Document
OVERVIEW
This section should provide a high-level narration of the program(s) purpose. The
requirements should be listed, the scope defined and the intended usage.
PROCESSING LOGIC
The processing should be defined by summarizing the control and data flow within the
main program. Techniques of process specification include Program Design
Language, Pseudo Code and Flow Charts.
The main program flow must be supplemented with the flow of
subroutines/methods/functions that are called from the main program.
Any specific algorithms to be used should be stated or referenced.
DATA (INPUT/OUTPUT)
The logical and physical data structure of files should be defined in detail. Data
structure definitions must include the:
a. description of each element, e.g. name, type, dimension;
b. relationships between the elements, i.e. the structure and source;
c. range of possible values of each element;
d. initial values of each element.
COMPONENTS (SOURCE CODE NAMES, CLASSES, METHODS)
Describe the software components (names or classes) and purpose that will be used.
Include UML class diagram showing the properties and methods of the class.
Describe the properties of the class and any constraints upon their value.
Indicate where the algorithms defined in processing logic are implemented.
TESTING
Present one or more named scenarios including the input data, expected output and
the success criteria desired that will be utilized to test the application. The testing
plan should be repeatable so discuss any ‘clean up’ that might be required to do so.
Example Scenario 1 – divide by zero test
Steps to test
Enter zero in the divisor.
Expected reaction
Expected results is a message saying ‘Zero is not a valid input. Please try
again’.
AY 2017-2018 DM
Purchase answer to see full
attachment
Economic Debate- Progressive Income Tax For this Economic Debate, we are going to discuss the…
TOPIC: Going Global Discussion Thread 1 (initial post due Wednesday for full credit) Please note:…
Assignment Topic This week will culminate in the creation of a narrated PowerPoint to create…
The Assignment must be submitted on Blackboard (WORD format only) via allocated folder. Assignments submitted…
you need to post your 2-page information flier to share with your Final Project Group.…
discussion: Discuss the methods used at your company to measure and ensure quality products and…