code here for getting the union and intersection of two sorted arrays. My problem is, i am a bit confused on the difference and the symmetric difference of those two arrays. Please help me with the difference and correct me if i made a mistake on the symmetric one. I would greatly appreciate it, thank you! :)  Here's my code:   void getUnion(int s1[], int count1, int s2[], int count2) { printf("\n\nARRAY SETS: \n"); printf("\nArray1: {1, 3, 5, 6, 8}\n"); printf("\nArray2: {2, 3, 5, 7}\n"); printf("\n---------------------\n"); printf("\nUNION\n"); int a = 0, b = 0; printf("\nThe union of two arrays are: \n"); while(a < count1 && b < count2) { if (s1[a] < s2[b]) printf("%d ", s1[a++]); else if (s2[b] < s1[a]) printf("%d ", s2[b++]); else { printf("%d ", s2[b]); a++; b++; } } while(a < count1) printf("%d ", s1[a++]); while(b < count2) printf("%d ", s2[b++]); } void intersection(int *s1, int count1, int *s2, int count2) { printf("\n\nINTERSECTION\n"); printf("\nIntersection of two arrays are: \n\n"); int c = 0, d = 0; while(c < count1 && d < count2) { if (s1[c] < s2[d])   c++; else if (s2[c] < s1[d])   d++; else { printf(" %d ", s2[c]);   c++;   d++; }}} void symmetricDifference(int *s1, int *s2, int count1, int count2) { printf("\n\nSYMMETRIC DIFFERENCE\n"); printf("\nDifference of two arrays are: \n\n"); int i = 0, j = 0; while (i < count1 && j < count2) { if (s1[i] < s2[j]) { printf("%d ", s1[i]); i++; } else if (s2[j] < s1[i]) { printf("%d ", s2[j]); j++; } else { i++; j++; } } }   int main(){ //get the union of two arrays getUnion(s1, 5, s2, 4); //get the intersection of two arrays intersection(s1, 5, s2, 4); //difference //-------------------code //symmetric difference symmetricDifference(s1, s2, 5, 4); }

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
100%

Hello, i have a code here for getting the union and intersection of two sorted arrays. My problem is, i am a bit confused on the difference and the symmetric difference of those two arrays. Please help me with the difference and correct me if i made a mistake on the symmetric one. I would greatly appreciate it, thank you! :) 

Here's my code:

 

void getUnion(int s1[], int count1, int s2[], int count2) {
printf("\n\nARRAY SETS: \n");
printf("\nArray1: {1, 3, 5, 6, 8}\n");
printf("\nArray2: {2, 3, 5, 7}\n");
printf("\n---------------------\n");
printf("\nUNION\n");

int a = 0, b = 0;
printf("\nThe union of two arrays are: \n");

while(a < count1 && b < count2) {

if (s1[a] < s2[b])

printf("%d ", s1[a++]);
else if (s2[b] < s1[a])

printf("%d ", s2[b++]);
else {

printf("%d ", s2[b]);
a++;
b++;
}

}

while(a < count1)
printf("%d ", s1[a++]);

while(b < count2)
printf("%d ", s2[b++]);

}

void intersection(int *s1, int count1, int *s2, int count2) {
printf("\n\nINTERSECTION\n");
printf("\nIntersection of two arrays are: \n\n");
int c = 0, d = 0;
while(c < count1 && d < count2) {
if (s1[c] < s2[d])
  c++;
else if (s2[c] < s1[d])
  d++;
else {
printf(" %d ", s2[c]);
  c++;
  d++;

}}}


void symmetricDifference(int *s1, int *s2, int count1, int count2)
{
printf("\n\nSYMMETRIC DIFFERENCE\n");
printf("\nDifference of two arrays are: \n\n");

int i = 0, j = 0;
while (i < count1 && j < count2)
{
if (s1[i] < s2[j])
{
printf("%d ", s1[i]);
i++;
}
else if (s2[j] < s1[i])
{
printf("%d ", s2[j]);
j++;
}
else
{
i++;
j++;
}
}
}

 

int main(){

//get the union of two arrays
getUnion(s1, 5, s2, 4);
//get the intersection of two arrays
intersection(s1, 5, s2, 4);
//difference
//-------------------code
//symmetric difference
symmetricDifference(s1, s2, 5, 4);
}

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
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