Question
Please convert this C code algorithm to complete Pseudocode. Please do it correctly and please put explain in it thankss!! #include #include int a=100; int
Please convert this C code algorithm to complete Pseudocode. Please do it correctly and please put explain in it thankss!!
#include
int a=100; int bits=0,total=0;
struct Queue1 { char data; unsigned freq; struct Queue *left, *right; };
struct Queue { int front, rear; int capa; struct Queue1** array; };
struct Queue1* newNode(char data, unsigned freq) { struct Queue1* temp = (struct Queue1*)malloc( sizeof(struct Queue1)); temp->left = temp->right = NULL; temp->data = data; temp->freq = freq; return temp; }
struct Queue* createQueue(int capa) { struct Queue* queue = (struct Queue*)malloc(sizeof(struct Queue)); queue->front = queue->rear = -1; queue->capa = capa; queue->array = (struct Queue1**)malloc( queue->capa * sizeof(struct Queue1*)); return queue; }
int sizeOne(struct Queue* queue) {
return queue->front == queue->rear && queue->front != -1; }
int Empty(struct Queue* queue) { return queue->front == -1; }
int Full(struct Queue* queue) { return queue->rear == queue->capa - 1; }
void ENQueue(struct Queue* queue, struct Queue1* item) { if (Full(queue)) return; queue->array[++queue->rear] = item; if (queue->front == -1) ++queue->front; }
struct Queue1* DEQueue(struct Queue* queue) { if (Empty(queue)) return NULL; struct Queue1* temp = queue->array[queue->front]; if (queue->front == queue ->rear) queue->front = queue->rear = -1; else ++queue->front; return temp; }
struct Queue1* Front(struct Queue* queue) { if (Empty(queue)) return NULL; return queue->array[queue->front]; }
struct Queue1* findMin(struct Queue* firstQueue, struct Queue* secondQueue) {
if (Empty(firstQueue)) return DEQueue(secondQueue);
if (Empty(secondQueue)) return DEQueue(firstQueue);
if (Front(firstQueue)->freq < Front(secondQueue)->freq) return DEQueue(firstQueue);
return DEQueue(secondQueue); }
int Leaf(struct Queue1* root) { return!(root->left) && !(root->right); }
void printArray(int arr[], int n,int freq) { int i; for (i = 0; i < n; ++i){ ++bits; } bits=bits*freq; printf("%d ",bits); total+=bits; bits=0; }
struct Queue1* createHuffmanTree(char data[], int freq[], int size) { struct Queue1 *left, *right, *tree;
struct Queue* firstQueue = createQueue(size); struct Queue* secondQueue = createQueue(size);
for (int i = 0; i < size; ++i) ENQueue(firstQueue, newNode(data[i], freq[i]));
while ( !(Empty(firstQueue) && sizeOne(secondQueue))) {
left = findMin(firstQueue, secondQueue); right = findMin(firstQueue, secondQueue);
tree = newNode('$', left->freq + right->freq); tree->left = left; tree->right = right; ENQueue(secondQueue, tree); }
return DEQueue(secondQueue); }
void pCodes(struct Queue1* root, int arr[], int idx) { // Assign 0 to left edge and recur if (root->left) { arr[idx] = 0; pCodes(root->left, arr, idx + 1); }
if (root->right) { arr[idx] = 1; pCodes(root->right, arr, idx + 1); }
if (isLeaf(root)) { printf("%c :",root->data); printArray(arr,idx,root->freq); } }
void HuffmanCodes(char data[], int freq[], int size) {
struct Queue1* root = createHuffmanTree(data, freq, size);
int arr[a], idx = 0; pCodes(root, arr, idx); }
int main() { char arr[] = { 'A', 'B', 'C', 'D', 'E', 'F','G','H','I','J','K','L','M','N','O','P'}; int freq[] = { 1 , 1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 3 , 3 , 4 , 4 , 4 }; int size = sizeof(arr) / sizeof(arr[0]); printf("Character: Total Bits: "); HuffmanCodes(arr, freq, size); printf("Total : %d",total); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started