Home > Back-end >  C to define a one-dimensional array for help!
C to define a one-dimensional array for help!

Time:09-27

Define a one dimensional array, the element number not more than 10 biggest, requirements:
1, write a ReadArray function to read the value of the individual elements in an array, and returns the number of array elements;
2, write a PrintArray function, each array element value output;
3, write a SortArray function, to give the individual elements of a one-dimensional array sorted, this function has three parameters: the one-dimensional array, the array length and sorting, if sorting is 1, in ascending order, if sorting way to 1, in descending order;
4, write a Delete function, in order to find the Delete a value in the array elements, if have the values in the array, is deleted in the array; If not, then output "this number cannot be found,"
5, write a Insert function, which is used to Insert an element in an ordered array, so that when the Insert array is orderly,
6, the requirements in the main function:
1) the first call ReadArray read number of array elements and statistical elements;
2) then calls the PrintArray output array elements;
3) and then receive the sort of user demands, it is ascending or descending order, call SortArray of sorted array accordingly;
4) calls PrintArray output again sorted array elements;
5) and then receives the user want to Delete the element value, call the Delete function to Delete the element;
6) call PrintArray after deleting the output of each element value;
7) and then receives the user to Insert the element value, call the Insert function, the element is inserted into the array,
8) calls PrintArray output array element value after insert,
will help you write, thank the

CodePudding user response:

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 

# pragma hdrstop

#include
#include

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

# pragma argsused
# define DATATYPE int
# define MAX 128

using namespace std;

Typedef struct
{
DATATYPE mArray (MAX);
Int mlen;
} Array;

Array myArray on;

Void ReadArray (Array *);
Void PrintArray (Array *);
Void SortArray (Array *);
Void DeleteElem (Array *, int);
Void InsertElem (Array *, int);

Int _tmain (int arg c, _TCHAR * argv [])
{
Int deleteelm insertelem;

ReadArray (& amp; MyArray on);
PrintArray (& amp; MyArray on);

SortArray (& amp; MyArray on);
PrintArray (& amp; MyArray on);

Cout & lt; Cin & gt;> Deleteelm;
DeleteElem (& amp; MyArray on deleteelm);
PrintArray (& amp; MyArray on);

Cout & lt; <"Insert:";
Cin & gt;> Insertelem.
InsertElem (& amp; MyArray on insertelem);
PrintArray (& amp; MyArray on);


system("PAUSE");
return 0;
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

CodePudding user response:

 void ReadArray (Array * pBegin) 
{
Cout & lt; Cin & gt;> PBegin - & gt; Mlen;
for(int i=0; i {
Cout & lt; <"[& lt; & lt;" I + 1 & lt; & lt; "]=";
Cin & gt;> PBegin - & gt; MArray [I];
}
}

CodePudding user response:

 void PrintArray (Array * pBegin) 
{
for(int i=0; i {
Cout & lt; }
Cout & lt; }
  • Related