Posts

Showing posts from January, 2024

Comparing Sleeping Barber Implementations in Java and Ada

Image
  Sleeping Barber Problem  Implemented in Ada and Java.  The Java implementation is taken from  Java Sleeping Barber. Problem Description: Simulate a barber shop with one barber, one barber chair and a waiting room with N chairs for waiting customers. When the barber finishes cutting the hair of one customer he dismisses the customer and goes to the waiting room to see if another customer is waiting. If the customer is waiting the barber cuts the customer's hair. If no customers are waiting the barber goes to sleep on the barber chair. The next customer to arrive must awaken the barber. If all waiting room chairs are full when a new customer arrives that arriving customer will leave the barbershop. If the barbershop is closed all arriving customers will leave the barbershop. The barber will cut the hair of all customers already in a chair when the barbershop closes. In these examples there are 4 chairs in the Barber Shop waiting room. ...

Comparing Array handling in C and Ada

  Problem Description: Find the Median of two merged sorted arrays. This article demonstrates some of the differences in array handling using the C language and the Ada language. C version: int* merge(int arr1[], size_t len1, int arr2[], size_t len2) {     int * const ret = malloc((len1 + len2) * sizeof(int));     int *wr = ret;       // merge the two arrays while they both have values     for(;len1 && len2; ++wr) {         if(*arr1 < *arr2) {                       *wr = *arr1++;             --len1;         } else {             *wr = *arr2++;             --len2;         }     }     // here either len1 or len2 or both are zero     // fill with any residue f...