---------------------------------------------------------------------------#pragma hdrstop#include <tchar.h> #include <iostream>//--------------------------------------------------------- ------------------#pragma argsused#define DATATYPE int#define MAX 128using Namespace std;typedef struct{datatype marray[max];int mlen;} Array; Array myarray;void readarray (array *); Void printarray (array *); Void SortArray ( array *); Void deleteelem (Array *, int); Void insertelem (array *, int); int _tmain (int argc, _tchar* argv[]) {int deleteelm, insertelem; Readarray (&myarray); PrintArray (&myarray); Sortarray (&myarray); PrintArray (&myarray);cout << "Delete:"; Cin >> deleteelm;deleteelem (& Myarray, deleteelm); PrintArray (&myarray);cout << "Insert:"; cin >> iNsertelem;insertelem (&myarray, insertelem); PrintArray (&myarray); System ("PAUSE"); return 0;} ---------------------------------------------------------------------------Void readarray (array * pbegin) //INPUT element {cout << "Len:"; cin >> pbegin->mlen;for (int i = 0; i < pbegin->mlen; i++) {cout << "[" < < i+1 << "] = "; cin >> pbegin->marray[i];}} Void printarray (array * pbegin) //output element {for (int i = 0; i < pbegin->mlen; i++) {cout << pbegin->marray[i] << "," ;} Cout << endl;} Void sortarray (Array * pbegin) //element Sort {for (int i= 1; i < pbegin->mlen; i++) {if (pbegin->marray[i] < pbegin->marray[i-1]) {&NBSP;&NBSP;&NBSP;&NBsp; int j= i-1;int x = pbegin-> Marray[i];p begin->marray[i] = pbegin->marray[i-1];while (X < pbegin->marray[j]) {pbegin->marray[j+1] = pbegin->marray[j];j--; }pbegin->marray[j+1] = x;}}} Void deleteelem (array * pbegin, int elem) //Delete element {for (int i = 0; i < pbegin->mlen; i++) {if (Pbegin->marray[i] == elem) { for (int j = i; j < pbegin->mlen; j++) { pbegin->marray[j] = pbegin->marray[j+1]; }pbegin->mlen--;}}} Void insertelem (Array * pbegin, int elem)//Insert element {Pbegin->marray[pbegin->mlen] = elem;pBegin->mlen++; Sortarray (Pbegin);}
Using C + + Builder to implement sorting and inserting operations for a set of arrays