Convert the C code below into Pseuedocode ______________________________________________________________ #include #define max 6 int count = 0, countSpan = 0, cost = 0; struct edge{     int x, y;     int value; }; edge list[max]; edge spanning[max]; int graph[max][max], n; int find(int *belong, int node){     return(belong[node]); } void sort(){   edge temp;   for (int i = 1; i < count; i++){     for (int j = 0; j < count - 1; j++){       if (list[j].value > list[j+1].value) {         temp = list[j];         list[j] = list[j+1];         list[j + 1] = temp;       }   }   } } void kruskal(){     int belong[max], node1, node2;     for(int i = 1; i < max; i++){         for(int j = 0; j < i; j++){       if(graph[i][j] != 0){               list[count].x = i;               list[count].y = j;               list[count].value = graph[i][j];               count++;       }         }     }     sort();   for(int i = 0; i < max; i++){     belong[i] = i;   }        for(int i = 0; i < max; i++){         node1 = find(belong, list[i].x);         node2 = find(belong, list[i].y);         if(node1 != node2){             spanning[countSpan] = list[i];             cost += spanning[countSpan].value;             countSpan++;             for(int i = 0; i < max; i++){             if(belong[i] == node2){                 belong[i] = node1;             }         }          }     } } void print(){   printf("%d\n", cost);   for (int i = 0; i < countSpan; i++){       printf("%c - %c : %d\n", spanning[i].y+65, spanning[i].x+65, spanning[i].value);       cost = cost + spanning[i].value;   } } int main(){   char a, b;   int value;   for(int i = 0; i < 12; i++){     scanf("%c", &a);     getchar();     scanf("%c", &b);     getchar();     scanf("%d", &value);     getchar();     list[i].value = value;     graph[a-'A'][b-'A'] = graph[b-65][a-65] = value;   }   kruskal();   print();        return 0; }

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

Convert the C code below into Pseuedocode

______________________________________________________________

#include <stdio.h>
#define max 6

int count = 0, countSpan = 0, cost = 0;

struct edge{
    int x, y;
    int value;
};

edge list[max];
edge spanning[max];
int graph[max][max], n;

int find(int *belong, int node){
    return(belong[node]);
}

void sort(){
  edge temp;
  for (int i = 1; i < count; i++){
    for (int j = 0; j < count - 1; j++){
      if (list[j].value > list[j+1].value) {
        temp = list[j];
        list[j] = list[j+1];
        list[j + 1] = temp;
      }
  }
  }
}

void kruskal(){
    int belong[max], node1, node2;
    for(int i = 1; i < max; i++){
        for(int j = 0; j < i; j++){
      if(graph[i][j] != 0){
              list[count].x = i;
              list[count].y = j;
              list[count].value = graph[i][j];
              count++;
      }
        }
    }

    sort();

  for(int i = 0; i < max; i++){
    belong[i] = i;
  }
  
    for(int i = 0; i < max; i++){
        node1 = find(belong, list[i].x);
        node2 = find(belong, list[i].y);
        if(node1 != node2){
            spanning[countSpan] = list[i];
            cost += spanning[countSpan].value;
            countSpan++;
            for(int i = 0; i < max; i++){
            if(belong[i] == node2){
                belong[i] = node1;
            }
        } 
        }
    }
}

void print(){
  printf("%d\n", cost);
  for (int i = 0; i < countSpan; i++){
      printf("%c - %c : %d\n", spanning[i].y+65, spanning[i].x+65, spanning[i].value);
      cost = cost + spanning[i].value;
  }
}

int main(){
  char a, b;
  int value;
  for(int i = 0; i < 12; i++){
    scanf("%c", &a);
    getchar();
    scanf("%c", &b);
    getchar();
    scanf("%d", &value);
    getchar();
    list[i].value = value;
    graph[a-'A'][b-'A'] = graph[b-65][a-65] = value;
  }

  kruskal();
  print();
  
    return 0;
}

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Graphical User Interface
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
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