我编的一个程序,是“插入排序(Insertion Sort)”
错误如下:1。error C2065: 'a' : undeclared identifier
2。error C2109: subscript requires array or pointer type
程序如下:
#include"iostream" #include"stdlib.h" using namespace std; void InsertionSort(int list[],int n){ //list the elements to be put into order //n the number of elements in the list int i,new_elem,location; for(i=2;i<=n;i++){ new_elem=list[i]; location=i-1; while(location>=1&&list[location]>new_elem){ list[location+1]=list[location]; location=location-1; }//while list[location+1]=new_elem; }//for cout<<"The new list is:"; for(i=1;i<=n;i++){ cout<<a[i]; cout<<"\n"; }//for }//InsertionSort void main(){ int a[101],i; a[0]=0; for(i=1;i<101;i++){//使用随机函数产生100个数字,分别赋给a[i] a[i]=rand()%100; a[0]++; }//for cout<<"\nThe original elements are:"; for(i=1;i<101;i++){ cout<<a[i]; cout<<"\n"; }//for InsertionSort(a,a[0]); }//main