New 14
New 14
#include "Array.h"
#include <stdio.h>
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
int i;
char c;
int state=0;
ptr->array[0]='\0';
do{
fflush(stdin);
{
printf("The input value is not valid! Please re-enter: ");
else
state =1;
}while(state != 1);
state = 0;
do{
fflush(stdin);
else
state =1;
}while(state != 1);
state =0;
{
int i;
printf("\nEmpty array!");
else
char ch;
else{
do{
fflush(stdin);
}
else
state = 1;
}while(state != 1);
ptr->NumMember++;
int i;
int val;
int k;
int state = 0;
char ch;
printf("\nEmpty array!");
else
do{
fflush(stdin);
else
state = 1;
}while(state != 1);
/* Delete element*/
for(i=k;i<=Num-2;i++)
ptr->array[i]=ptr->array[i+1];
ptr->NumMember = Num-1;
else
int i;
int j;
int val;
{
for(j=i+1; j< ptr->NumMember; j++)
if(ptr->array[i]> ptr->array[j] )
val= ptr->array[i];
ptr->array[i]=ptr->array[j];
ptr->array[j]=val;
int i;
int j;
int val;
if(ptr->array[i]< ptr->array[j] )
val= ptr->array[i];
ptr->array[i]=ptr->array[j];
ptr->array[j]=val;
int i;
int Index[ptr->NumMember];
int count=0;
int Elem;
int state = 0;
char ch;
do{
fflush(stdin);
else
state = 1;
}while(state != 1);
for(i=0; i<ptr->NumMember;i++)
if(ptr->array[i] == Elem)
Index[count]=i;
count++;
}
if(0 == count)
else
for(i=0;i<count;i++)
printf("%d\t",Index[i]);
file.h
#ifndef H_ARRAY_H
#define H_ARRAY_H
/*******************************************************************************
* Definitions
******************************************************************************/
#define N 100
}List;
/*******************************************************************************
* API
******************************************************************************/
#endif /*H_ARRAY_H*/
main.c
#include <stdio.h>
#include "Array.h"
#include <string.h>
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
int main() {
List array;
char choice[10];
do {
system("cls");
printf("\n================================================");
do{
gets(choice);
if(1 == strlen(choice))
state =1;
else
}
}while(state !=1);
state =0;
switch(choice[0]) {
case 'c':
InputArray(&array);
fflush(stdin);
getch();
break;
case 'p':
OutputArray(&array);
fflush(stdin);
getch();
break;
case 'i':
InsertEND(&array);
fflush(stdin);
getch();
break;
case 'd':
DeleteIndex(&array);
fflush(stdin);
getch();
break;
case 's':
getch();
break;
case 'x':
SortArrayG(&array);
getch();
break;
case 't':
SearchElement(&array);
fflush(stdin);
getch();
break;
case 'e':
system("cls");
printf("\nExit program");
break;
default:
printf("Invalid choice");
getch();
break;
} while(choice[0] != 'e');