#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include "ARRAY1.h"
#include "MYTOOLS.h"
#define SIZE 100



void main(){

int ray=0, la[SIZE],bh=0, ho=0, ebe, ri, t, p, r=1, g;
char sw, c, ch;


do{
drawbox();
printf("\nEnter your choice: ");
scanf("%s", &sw);
switch(sw){
case 'a':
case 'A':
printf("\nEnter how many numbers you want to input: ");
scanf("%d", &ray);
printf("\nEnter the numbers: ");
createArray(la, ray);
printf("\nSuccessfuly created an array.\nNow press b to view the numbers you entered.");
printf("\n ");

break;
case 'b':
case 'B':
if(la[SIZE]=='\0')
printf("Array is empty.");
else{
printf("These are the items in your array: ");
printArray(la, ray);
}

break;
case 'c':
case 'C':
if(la[SIZE]=='\0')
printf("Array is empty.");
else{
printf("Enter the number you want to ensert: ");
scanf("%d", &bh);
printf("At what position do you want it to be inserted: ");
scanf("%d", &ho);
if(inserAtPos(la, ray, bh, ho)==1){
ray=ray+1;
printf("Item successfuly inserted!");
}}

break;
case 'd':
case 'D':
if(la[SIZE]=='\0')
printf("Array is empty.");
else{
printf("Enter the number you want to insert in front: ");
scanf("%d", &bh);
insertFront(la, ray, bh);
ray=ray+1;
printf("Item successfuly inserted in front of the list!");
}

break;

case 'e':
case 'E':
if(la[SIZE]=='\0')
printf("Array is empty.");
else{

while(r==1){
for(p=0; p<ray;p++){
printf("\n(position %d)-- %d", p+1, la[p]);

}

printf("\nEnter the position of the item you want to remove: ");
scanf("%d", &ebe);
if (ebe<ray+1){
r=0;
removeAtPos(la, ray, ebe);
ray=ray-1;
printf("Item successfuly removed at the given position!");

}
else{
printf("\n");
printf("Enter a correct position!");
printf("\n");
}
}
}
r=1;
break;

case 'f':
case 'F':
if(la[SIZE]=='\0')
printf("Array is empty.");
else{
printArray(la, ray);
printf("\nEnter the item you want to remove: ");
scanf("%d", &ri);
if(removeItem(la, ray, ri)==1){
ray=ray-1;
printf("Item successfuly removed!");
}
else
printf("Item not in the list!");
}
break;

case 'g':
case 'G':
if(la[SIZE]=='\0')
printf("Array is empty.");
else{
if(removeFront(la, ray)==1)
ray=ray-1;
}
break;

case 'h':
case 'H':
if(la[SIZE]=='\0')
printf("Array is empty.");
else{
printf("Enter the item you want to search if its in the list: ");
scanf("%d", &t);
locateIndex(la, ray, t);
}

break;

case 'j':
case 'J':
if(la[SIZE]=='\0')
printf("Array is empty.");
else{
sortAscending(la, ray);
sortDescending(la, ray);
}

break;

case 'k':
case 'K':
exit(0);

break;

case 'i':
case 'I':
printf("Enter the item you want to search if its in the list: ");
scanf("%d", &g);
locateItem(la, ray, g);


break;

}
printf("\n");
printf("\nRun again?(y/n)");
ch = getch();

if(ch=='y'||ch=='Y'){
c=1;
system("cls");
}
else{
c=0;
}

fflush(stdin);
}while(c==1);

}