Bubblesort and nonduplicates

Error message states: "stack around variable 'a' was corrupted."

#include <iostream>
#include <iomanip>
using std::cin;
using std::cout;
using std::endl;
using std::setw;
const int SIZE=12;
//void distributeElements(int a[], int b[]);
void collectElements (int[], int b[]);
//int buckets[];
void bubbleSort( int a[], int last);
int main(){
/*double a[11], b[34];*/
int i;
int j;
int n;
int subscript;
/*const int a=11;
const int b=34;*/

int a[11]={2,4,12,1,1,1,5,2,3,3,4};

void bubbleSort( int a[], int last);
{
int temp;
int last=10;
for (int current=0; current<last; current++)
{
//Inner loop: bubble up one element each pass
for( int walker=last;
walker>current;
walker--)
if (a[walker]<a[walker-1])
{
temp=a[walker];
a[walker]=a[walker-1];
a[walker-1]=temp;
}

}//end bubblesort
}
int b[34]={};
//int insert;
//add
for (int i=0; i<0; i++){


// insert=b[i];//store the value in the current element
//int moveItem=i;
collectElements (a, b);
/* a[i]=b[j];*/
cout<<setw(5)<<a[i]<<endl<<'\n';
cout<<setw(5)<<b[i];}
cin>>b[11];
return 0;
}

//void distributeElements(int a[], int b[]){
//
//
//int elementNumber;
//int i;
//
//for (int k=0; k<11; k++){
//
// elementNumber=++b[0];
// b[i]=a[k];}
//}
void collectElements (int a[], int b[])
{
int subscript = 0;
int n;
int i;
/*int j;*/
/*int printFlag;
int subscript=0;
int temp=n;*/
int duplicate=0;
for (int n=9; ;){///for i=0..10

if (a[1]=a[9-1]){
duplicate=1;
break;}}
/*if (a[i]=a[9-i]){
b[i]=a[i];}
if (a[i]=a[8-i]){
b[i]=a[i];}
if (a[i]=a[7-i]){
b[i]=a[i];}
if (a[i]=a[6-i]){
b[i]=a[i];}
if (!duplicate){
a[subscript++]=b[i];
i++;}*/
/*if (!duplicate)
{
a[subscript++]=a[i];
i++;}
else*/
cout<<"This number is a duplicate";}
/*case 7: a[i]=a[7-i];
b[i]=a[i];*/
/*for (int n=9;n=9,7,5,3,1;n--){

if (a[i]==a[i-n])
printFlag=1;
break;
if (!printFlag)
a[subscript++]=a[i];
i++;*/



//if not duplicate

//if (int a[i+1]=b[n-i]);//for n=1..10
//if (int a[2]=a[n-2]){
//
// printFlag=1;
// cout<<"1";
// break;
//if (a[i]!=a[n-1])
// b[i]=a[i];
// continue;


/*a[i]=a[i-2]*///do not move duplicate to 2nd array
// a[i]!=a[j];//where a[j] is is any element other than a[i];
// for (int i=0; i!=j; i= 2,4,6,8,10)

//(a[i]=a[i-3])
//
//if (b[j]<a[i]
//b[i]=a[i];}
/* cout<<setw(5)<<a[k];*/

]
Use code tags. It makes your code more readable.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <iostream>
 #include <iomanip>
 using std::cin;
 using std::cout;
 using std::endl;
 using std::setw;
 const int SIZE=12;
 //void distributeElements(int a[], int b[]);
 void collectElements (int[], int b[]);
 //int buckets[];
 void bubbleSort( int a[], int last);
 int main(){
 /*double a[11], b[34];*/
 int i;
 int j;
 int n;
 int subscript;
 /*const int a=11;
 const int b=34;*/

 int a[11]={2,4,12,1,1,1,5,2,3,3,4};

 void bubbleSort( int a[], int last);
 {
 int temp;
 int last=10;
 for (int current=0; current<last; current++)
 {
 //Inner loop: bubble up one element each pass
 for( int walker=last;
 walker>current;
 walker--)
 if (a[walker]<a[walker-1])
 {
 temp=a[walker];
 a[walker]=a[walker-1];
 a[walker-1]=temp;
 }

 }//end bubblesort
 }
 int b[34]={};
 //int insert;
 //add
 for (int i=0; i<0; i++){


 // insert=b[i];//store the value in the current element
 //int moveItem=i;
 collectElements (a, b);
 /* a[i]=b[j];*/
 cout<<setw(5)<<a[i]<<endl<<'\n';
 cout<<setw(5)<<b[i];}
 cin>>b[11];
 return 0;
 }

 //void distributeElements(int a[], int b[]){
 //
 //
 //int elementNumber;
 //int i;
 //
 //for (int k=0; k<11; k++){
 //
 // elementNumber=++b[0];
 // b[i]=a[k];}
 //}
 void collectElements (int a[], int b[])
 {
 int subscript = 0;
 int n;
 int i;
 /*int j;*/
 /*int printFlag;
 int subscript=0;
 int temp=n;*/
 int duplicate=0;
 for (int n=9; ;){///for i=0..10

 if (a[1]=a[9-1]){
 duplicate=1;
 break;}}
 /*if (a[i]=a[9-i]){
 b[i]=a[i];}
 if (a[i]=a[8-i]){
 b[i]=a[i];}
 if (a[i]=a[7-i]){
 b[i]=a[i];}
 if (a[i]=a[6-i]){
 b[i]=a[i];}
 if (!duplicate){
 a[subscript++]=b[i];
 i++;}*/
 /*if (!duplicate)
 {
 a[subscript++]=a[i];
 i++;}
 else*/
 cout<<"This number is a duplicate";}
 /*case 7: a[i]=a[7-i];
 b[i]=a[i];*/
 /*for (int n=9;n=9,7,5,3,1;n--){

 if (a[i]==a[i-n])
 printFlag=1;
 break;
 if (!printFlag)
 a[subscript++]=a[i];
 i++;*/



 //if not duplicate

 //if (int a[i+1]=b[n-i]);//for n=1..10
 //if (int a[2]=a[n-2]){
 // 
 // printFlag=1;
 // cout<<"1";
 // break;
 //if (a[i]!=a[n-1]) 
 // b[i]=a[i];
 // continue;


 /*a[i]=a[i-2]*///do not move duplicate to 2nd array
 // a[i]!=a[j];//where a[j] is is any element other than a[i];
 // for (int i=0; i!=j; i= 2,4,6,8,10)

 //(a[i]=a[i-3])
 //
 //if (b[j]<a[i]
 //b[i]=a[i];}
 /* cout<<setw(5)<<a[k];*/

 ] 


Topic archived. No new replies allowed.