I have these two questions sloved but can you just look into to codes why singed and unsigned little looks diffrnet is that I can use one structure for both codes. for example can I use unassigned answer to the singed one ?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I have these two questions sloved but can you just look into to codes why singed and unsigned little looks diffrnet is that I can use one structure for both codes. for example can I use unassigned answer to the singed one ? this is not grading question this is prof gave for practice and I wrote my codes so do not reject all i need to know can I use unsiged answer to singed 

File Edit View
Problem 17 (Unsigned integer radix sort - ): Write a C program for sorting 32-bit unsigned integers
using radix sort with a group of 4 bits. Use the variables listed below. Assume 1st is initialized with n numbers.
#define N 1048576
#define BIN 256
#define MAXBIT 32
#define LST 1
#define BUF @
int n, group, bin;
int flag; /* to show which one holds numbers: 1st or buf */
int 1st[N], buf[N];
int count [BIN], map[BIN], tmap [BIN];
int main(int argc, char **argv) {
int i;
flag = LST;
initialize(); /* initialize 1st with n random floats */
for (i = 0; i < MAXBIT; i = i + group)
radix_sort(i); /* move 1st to buf or buf to 1st depending on the iteration number */
correct(); /* sorted numbers must be in 1st */
}
void radix_sort(int idx) {
int i, j, k, mask; /* initialize mask for lifting the 4 least significant bits. */
int *src_p, *dst_p; /* cast 1st and buf to int pointers to treat 1st/buf as int's */
/* set src_p and dst_p */
}
if (flag == LST) {
src_p= 1st; /* Set src_p to 1st */
dst_p = buf; /* Set dst_p to buf */
} else {
src_p buf; /* Set src_p to buf */
dst_p=1st; /* Set dst_p to 1st */
}
flag
(flag ==LST)? BUF: LST;
mask = 0xF; /* 4 bits mask /
=
/* count */
for (i = 0; i < BIN; i++) {
count[i] = 0;
}
for (i = 0; i < N;i++) {
count[(src_p[i] >> idx) & mask]++;
}
/* map /
map[0] = 0;
for (i = 1; i < BIN; i++) {
}
/* move */
for (i = 0; i < N;i++) {
dst_p[map[(src_p[i] >> idx) & mask]++] = src_p[i];
}
map[i] = map[i-1]+ count[i-1];
}
void correct() {
int i;
if (flag == LST) {
for (i = 0; i < N;i++) {
1st[i] = buf[i];
}
} else {
for (i = 0; i < N; i++) {
buf[i] 1st[i];
=
}
Transcribed Image Text:File Edit View Problem 17 (Unsigned integer radix sort - ): Write a C program for sorting 32-bit unsigned integers using radix sort with a group of 4 bits. Use the variables listed below. Assume 1st is initialized with n numbers. #define N 1048576 #define BIN 256 #define MAXBIT 32 #define LST 1 #define BUF @ int n, group, bin; int flag; /* to show which one holds numbers: 1st or buf */ int 1st[N], buf[N]; int count [BIN], map[BIN], tmap [BIN]; int main(int argc, char **argv) { int i; flag = LST; initialize(); /* initialize 1st with n random floats */ for (i = 0; i < MAXBIT; i = i + group) radix_sort(i); /* move 1st to buf or buf to 1st depending on the iteration number */ correct(); /* sorted numbers must be in 1st */ } void radix_sort(int idx) { int i, j, k, mask; /* initialize mask for lifting the 4 least significant bits. */ int *src_p, *dst_p; /* cast 1st and buf to int pointers to treat 1st/buf as int's */ /* set src_p and dst_p */ } if (flag == LST) { src_p= 1st; /* Set src_p to 1st */ dst_p = buf; /* Set dst_p to buf */ } else { src_p buf; /* Set src_p to buf */ dst_p=1st; /* Set dst_p to 1st */ } flag (flag ==LST)? BUF: LST; mask = 0xF; /* 4 bits mask / = /* count */ for (i = 0; i < BIN; i++) { count[i] = 0; } for (i = 0; i < N;i++) { count[(src_p[i] >> idx) & mask]++; } /* map / map[0] = 0; for (i = 1; i < BIN; i++) { } /* move */ for (i = 0; i < N;i++) { dst_p[map[(src_p[i] >> idx) & mask]++] = src_p[i]; } map[i] = map[i-1]+ count[i-1]; } void correct() { int i; if (flag == LST) { for (i = 0; i < N;i++) { 1st[i] = buf[i]; } } else { for (i = 0; i < N; i++) { buf[i] 1st[i]; = }
Problem 16 (Signed integer radix sort): Write a C program for sorting 32-bit signed integers using
radix sort with a group of 8 bits. Use the variables listed below. Assume 1st is initialized with n numbers
#define N 1048576
#define BIN 256
#define MAXBIT 32
#define LST 1
#define BUF @
int n, group, bin;
int flag; /* to show which one holds numbers: 1st or buf */
int 1st[N], buf[N];
int count [BIN], map[BIN], tmap [BIN];
int main(int argc, char **argv) {
int i;
flag = LST;
initialize(); /* initialize 1st with n random floats */
for (i = 0; i < MAXBIT; i = i + group)
radix_sort(i); /* move 1st to buf or buf to 1st depending on the iteration number */
correct(); /* sorted numbers must be in 1st */
}
void radix_sort(int idx) {
int i, j, k, mask; /* initialize mask for lifting the 4 least significant bits. */
int src_p, dst_p; /* cast 1st and buf to int pointers to treat 1st/buf as int's */
/* set src_p and dst_p */
if (flag == LST) {
src_p= 1st; /* Set src_p to 1st /
dst_p= buf; /* Set dst_p to buf */
} else {
}
src_p= buf; /* Set src_p to buf */
dst_p= 1st; /* Set dst_p to 1st */
}
// Initialize mask for lifting the least significant bits
mask = (1 << group) - 1;
/ count */
// Initialize count array
for (i = 0; i < bin; i++) {
count[i] = 0;
}
// Count the occurrences of each bin value
for (i = 0; i<n; i++) {
j= (src_p[i]>> idx) & mask;
count [j]++;
}
/* map /
// Compute the starting position of each bin value in the map array
map[0] = 0;
for (i = 1; i < bin; i++) {
}
/* move */
// Move elements from src_p to dst_p based on the computed positions
for (i = 0; i< n; i++) {
map[i] = map[i-1] + count[i-1];
j= (src_p[i]>> idx) & mask;
k = map[j]++;
dst_p[k] = src_p[i];
}
void correct() {
// Sorted numbers must be in 1st
if (flag == BUF) {
// Copy numbers from buf to 1st
for (int i _ a. i zn. iaal S
Ln 3, Col 1
60%
Windows (CRLF)
Transcribed Image Text:Problem 16 (Signed integer radix sort): Write a C program for sorting 32-bit signed integers using radix sort with a group of 8 bits. Use the variables listed below. Assume 1st is initialized with n numbers #define N 1048576 #define BIN 256 #define MAXBIT 32 #define LST 1 #define BUF @ int n, group, bin; int flag; /* to show which one holds numbers: 1st or buf */ int 1st[N], buf[N]; int count [BIN], map[BIN], tmap [BIN]; int main(int argc, char **argv) { int i; flag = LST; initialize(); /* initialize 1st with n random floats */ for (i = 0; i < MAXBIT; i = i + group) radix_sort(i); /* move 1st to buf or buf to 1st depending on the iteration number */ correct(); /* sorted numbers must be in 1st */ } void radix_sort(int idx) { int i, j, k, mask; /* initialize mask for lifting the 4 least significant bits. */ int src_p, dst_p; /* cast 1st and buf to int pointers to treat 1st/buf as int's */ /* set src_p and dst_p */ if (flag == LST) { src_p= 1st; /* Set src_p to 1st / dst_p= buf; /* Set dst_p to buf */ } else { } src_p= buf; /* Set src_p to buf */ dst_p= 1st; /* Set dst_p to 1st */ } // Initialize mask for lifting the least significant bits mask = (1 << group) - 1; / count */ // Initialize count array for (i = 0; i < bin; i++) { count[i] = 0; } // Count the occurrences of each bin value for (i = 0; i<n; i++) { j= (src_p[i]>> idx) & mask; count [j]++; } /* map / // Compute the starting position of each bin value in the map array map[0] = 0; for (i = 1; i < bin; i++) { } /* move */ // Move elements from src_p to dst_p based on the computed positions for (i = 0; i< n; i++) { map[i] = map[i-1] + count[i-1]; j= (src_p[i]>> idx) & mask; k = map[j]++; dst_p[k] = src_p[i]; } void correct() { // Sorted numbers must be in 1st if (flag == BUF) { // Copy numbers from buf to 1st for (int i _ a. i zn. iaal S Ln 3, Col 1 60% Windows (CRLF)
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Binary numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education