Question: Compelye C Code for all functions. also orovide pseudocode for functions #include #include void removeAt(int a[], int l, int* n); void printList(int a[], int *n);
Compelye C Code for all functions. also orovide pseudocode for functions
#include
#include
void removeAt(int a[], int l, int* n);
void printList(int a[], int *n);
int main()
{
int a[] = {2,9,3,9};
int arraySize = sizeof(a)/sizeof(a[0]);
int* n = &arraySize;
int l, loc;
int choice;
while(1)
{
printf(" Main Menu");
printf(" 1.Create 2.Insert 3.Delete an Element 4. Remove Element at Position 5.Replace an element at given position 6. Check the size of the list 7. Check if the list is empty 8. Check if the list is full 9. Print the current List 10. Exit ");
printf(" Enter your Choice \t");
scanf("%d", &choice);
switch(choice)
{
case 1: //Create
printf(" Enter elements you want in your array:");
scanf("%d", &l);
break;
case 2: //Insert
printf(" Enter the position you want to insert: ");
scanf("%d", &l);
removeAt(a, l, n);
break;
case 3: //Delete an Element
case 4: //Remove At
printf(" Enter the position you want to delete::");
scanf("%d", &l);
removeAt(a, l, n);
break;
case 5: //Replace At
case 6: //Check size of list
case 7: // Check if empty
case 8:
case 9: //Print current element
printList(a, n);
break;
case 10:
exit(0);
break;
default:
printf(" Enter the correct choice:");
}
}
}
void removeAt(int a[], int pos, int* size)
{
int i;
// if (isEmpty(size) ==1){
if (pos > (*size))
printf("Error: invalid location ");
else {
for (i = pos; i < (*size); i++){
a[i - 1] = a[i];
}
}
}
//else
// printf("Error: List is empty ");
(*size)--;
printList(a, size);
}
// removeAt(a, loc)
// n = sizeof(a)
// if (loc > n)
// error: invalid location
// else
// for (loc =n + 1 to n)
// a[loc] = a[loc + 1]
// n = sizeof(a)
// n = n - 1
int isEmpty(int *n) {
if (*n <= 0) {
return 0;
}
else
return 1;
}
void printList(int a[], int* size)
{
printf(" The Elements of The list ADT are:");
for(int i=0;i<(*size);i++)
{
printf(" %d", a[i]);
}
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
