10 11 12 13 insertion_Sort(A, n); printf("The sorted array is: "); 14 15 16 17 -0-0 for (int i = 0; i < 6; i++) { if (i == 5) { printf("%d", A[i]); printf(" } 18 else 19 20 } 21 22 return 0; 23 } 24 25 26 27 int j; 28 int i; 29 3 3 30 31 = key i = A[i]; 1; ✔ No issues found void insertion_Sort( int key; Exception Thrown Exception thrown at 0x00007FF62DB018AA in Algorithms Testing2.exe: 0xC0000005: Access violation reading location Show Call Stack | Copy Details | Start Live Share session... Exception Settings Break when this exception type is thrown Except when thrown from: Algorithms Testing2.exe Open Exception Settings Edit Conditions for (i = 2; i <= n / 1++) { h (Ctrl+E) ne ЭА Si key n Search Depth: 3 Value 0x00000000feeff5d8 {???} 2 0 32758 6 Type int * int int int int - дх Output ДХ Show output from: Debug 'Algorithms Testing2.exe' (Win32): Loa 'Algorithms Testing2.exe' (Win32): Loa 'Algorithms Testing2.exe' (Win32): Loa 'Algorithms Testing2.exe' (Win32): Loa 'Algorithms Testing2.exe' (Win32): Loa 'Algorithms Testing2.exe' (Win32): Loa The thread 0x1940 has exited with code Exception thrown at 0x00007FF62DB018AA

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 19RQ
icon
Related questions
Question

I am trying to write an insertion sort program, but I keep getting an exeception thrown message. What is causing this?

Here is my code: 

#include <stdio.h>
 
 
void insertion_Sort(int, int);
 
int main() {
 
int A[] = { 5, 2, 4, 6, 1, 3 };
int n = 6;
 
insertion_Sort(A, n);
 
printf("The sorted array is: ");
for (int i = 0; i < 6; i++) {
if (i == 5) {
printf("%d", A[i]);
}
else
printf("%d,", A[i]);
}
 
return 0;
}
 
void insertion_Sort(int A[], int n) {
int key;
int j;
int i;
for (i = 2; i <= n; i++) {
key = A[i];
j = i - 1;
while (j > 0 && A[j] > key) {
A[j + 1] = A[j];
j = j - 1;
}
A[j + 1] = key;
 
}
}
10
11
12
13
insertion_Sort(A, n);
printf("The sorted array is: ");
14
15
16
17
-0-0
for (int i =
0; i < 6; i++) {
if (i == 5) {
printf("%d", A[i]);
printf("
}
18
else
19
20
}
21
22
return 0;
23
}
24
25
26
27
int j;
28
int i;
29
3 3
30
31
=
key
i
=
A[i];
1;
✔ No issues found
void insertion_Sort(
int key;
Exception Thrown
Exception thrown at 0x00007FF62DB018AA in Algorithms
Testing2.exe: 0xC0000005: Access violation reading location
Show Call Stack | Copy Details | Start Live Share session...
Exception Settings
Break when this exception type is thrown
Except when thrown from:
Algorithms Testing2.exe
Open Exception Settings Edit Conditions
for (i = 2; i <= n / 1++) {
h (Ctrl+E)
ne
ЭА
Si
key
n
Search Depth: 3
Value
0x00000000feeff5d8 {???}
2
0
32758
6
Type
int *
int
int
int
int
- дх
Output
ДХ
Show output from: Debug
'Algorithms Testing2.exe' (Win32): Loa
'Algorithms Testing2.exe' (Win32): Loa
'Algorithms Testing2.exe' (Win32): Loa
'Algorithms Testing2.exe' (Win32): Loa
'Algorithms Testing2.exe' (Win32): Loa
'Algorithms Testing2.exe' (Win32): Loa
The thread 0x1940 has exited with code
Exception thrown at 0x00007FF62DB018AA
Transcribed Image Text:10 11 12 13 insertion_Sort(A, n); printf("The sorted array is: "); 14 15 16 17 -0-0 for (int i = 0; i < 6; i++) { if (i == 5) { printf("%d", A[i]); printf(" } 18 else 19 20 } 21 22 return 0; 23 } 24 25 26 27 int j; 28 int i; 29 3 3 30 31 = key i = A[i]; 1; ✔ No issues found void insertion_Sort( int key; Exception Thrown Exception thrown at 0x00007FF62DB018AA in Algorithms Testing2.exe: 0xC0000005: Access violation reading location Show Call Stack | Copy Details | Start Live Share session... Exception Settings Break when this exception type is thrown Except when thrown from: Algorithms Testing2.exe Open Exception Settings Edit Conditions for (i = 2; i <= n / 1++) { h (Ctrl+E) ne ЭА Si key n Search Depth: 3 Value 0x00000000feeff5d8 {???} 2 0 32758 6 Type int * int int int int - дх Output ДХ Show output from: Debug 'Algorithms Testing2.exe' (Win32): Loa 'Algorithms Testing2.exe' (Win32): Loa 'Algorithms Testing2.exe' (Win32): Loa 'Algorithms Testing2.exe' (Win32): Loa 'Algorithms Testing2.exe' (Win32): Loa 'Algorithms Testing2.exe' (Win32): Loa The thread 0x1940 has exited with code Exception thrown at 0x00007FF62DB018AA
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage