Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help to finish my following code: Some errors I have no ideas to fix them

ID: 3677329 • Letter: I

Question

I need help to finish my following code: Some errors I have no ideas to fix them (void tbl_sort(Tablet*t, int col, int incr) part.

You will write an implementation of radix sort which behaves as follows:

It reads a sequence of non-negative integers from standard input. The number of values to be read (N) is not given to you ahead of time.

The program reads non-negative integers until it reaches EOF or an attempt to read an unsigned int fails (e.g., there is a “token” in the input that cannot be parsed as a non-negative integer). In the latter case, the program itself does not “fail”; it simply sorts the values it did successfully read.

Sorts them using Radix Sort with a radix of N (or near N -- more on this below).

Displays the data in sorted order.

You will submit a single source file rsort.c containing your implementation.

You will submit all necessary files to create your rsort executable in a single archive file. Among the files should be a Makefile supporting

$ make rsort

Example: If your implementation utilizes the list ADT from the first programming assignment (and so your executable links with llist.o), you must, of course, include the related source files (list.h and llist.c).

#include <stdio.h>
#include <string.h>
#include <stdlib.h>


// typedef unsigned int size_t;
#define MAX_SIZE 500
#define swap(p, q, size) {
char *t;
t = malloc(size);
memcpy(t, p, size);
memcpy(p, q, size);
memcpy(q, t, size);
free(t);
}

void _qsort(void *base, size_t n, size_t size, int (*cmp)(const void *, const void *))
{
char *p, *q, *hi, *lo;
size_t i;
if (n < 2)
return ;
if (n == 2) {
p = (char *)base + size;
if ((*cmp)(base, p) > 0)
swap(base, p, size)
return ;
}
lo = (char *)base;
hi = (char *)base + size * (n - 1);
p = lo + size;
q = hi;
while (1) {
for (; p <= hi && (*cmp)(p, lo) < 0; p += size) ;
for (; q > lo && (*cmp)(q, lo) > 0; q -= size) ;
if (p < q)
swap(p, q, size)
else {
if (q != lo)
swap(lo, q, size)
break;
}
}
_qsort(lo, (q - lo) / size, size, cmp);
_qsort(q + size, (hi - q) / size, size, cmp);
return ;
}

void tbl_sort (Table *t, int col, int incr){
   qsort (t->rows, t->nrows,sizeof(Row),cmp)
}

int intcmp(const int *a, const int *b){
   Row *ra=(Row*)a;
   Row *rb=(Row*)b;
  
   if (ra->vals[col]<rb->vals[col])
   return -1;
   if (rb->vals[col]<ra->vals[col])
   return 1;
   else
   return 0;
}
#define STR_LEN 20
main()
{
int i, n;
// char base[MAX_SIZE][STR_LEN];
int nums[MAX_SIZE];
  
for (i = 0; i < MAX_SIZE && scanf("%d", &nums[i]) != EOF; i++) ;
n = i;
for (i = 0; i < n; i++)
printf("%d ", nums[i]);
putchar(' ');

// my _qsort function
_qsort(nums, n, sizeof(int), (int (*)(const void *, const void *))intcmp);

for (i = 0; i < n; i++)
printf("%d ", nums[i]);
putchar(' ');
}

Explanation / Answer

Hi, I have attachingg simle radix-sort implementation. You can take reference of this.

// C++ implementation of Radix Sort
#include<iostream>
using namespace std;

// A utility function to get maximum value in arr[]
int getMax(int arr[], int n)
{
int mx = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > mx)
mx = arr[i];
return mx;
}

// A function to do counting sort of arr[] according to
// the digit represented by exp.
void countSort(int arr[], int n, int exp)
{
int output[n]; // output array
int i, count[10] = {0};

// Store count of occurrences in count[]
for (i = 0; i < n; i++)
count[ (arr[i]/exp)%10 ]++;

// Change count[i] so that count[i] now contains actual
// position of this digit in output[]
for (i = 1; i < 10; i++)
count[i] += count[i - 1];

// Build the output array
for (i = n - 1; i >= 0; i--)
{
output[count[ (arr[i]/exp)%10 ] - 1] = arr[i];
count[ (arr[i]/exp)%10 ]--;
}

// Copy the output array to arr[], so that arr[] now
// contains sorted numbers according to current digit
for (i = 0; i < n; i++)
arr[i] = output[i];
}

// The main function to that sorts arr[] of size n using
// Radix Sort
void radixsort(int arr[], int n)
{
// Find the maximum number to know number of digits
int m = getMax(arr, n);

// Do counting sort for every digit. Note that instead
// of passing digit number, exp is passed. exp is 10^i
// where i is current digit number
for (int exp = 1; m/exp > 0; exp *= 10)
countSort(arr, n, exp);
}

// A utility function to print an array
void print(int arr[], int n)
{
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
}

// Driver program to test above functions
int main()
{
int arr[] = {170, 45, 75, 90, 802, 24, 2, 66};
int n = sizeof(arr)/sizeof(arr[0]);
radixsort(arr, n);
print(arr, n);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote