Home > Back-end >  C language implementation of menu set series, intersection, difference set, feeling under optimized
C language implementation of menu set series, intersection, difference set, feeling under optimized

Time:09-26



 # include 
using namespace std;
//main menu
Void menu () {
cout<" * * * * * * * * * * * Welcome! * * * * * * * * * "& lt; & lt; Endl;
cout<" * * * * * * * 1 input set A, B * * * * * * * * "& lt; & lt; Endl;
cout<" * * * * * * * 2 set for A/B * * * * * * * * * "& lt; & lt; Endl;
cout<" * * * * * * * 3 please set A and B * * * * * * * * * "& lt; & lt; Endl;
cout<" * * * * * * * 4 o set A minus B * * * * * * * * * "& lt; & lt; Endl;
cout<" Negative out of * * * * * * * * * * * * * * * "& lt; & lt; Endl;
cout<" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "& lt; & lt; Endl;
}
//set element collection
Void collect (int shun, int n, int a []) {
Int I, j, k;
for(i=0; icout<" Please enter the first "& lt; & lt; Shun<" A collection of the first "& lt; & lt; I + 1 & lt; <" Element: ";
Cin> A, [I].
While (a [I] <=0) {
cout<" Please enter a positive integer again: ";
Cin> A, [I].
}
//from the input of the second number began to judge whether there is duplicate values
If (i> 0 {
For (j=I, k=0; KWhile (a [k]==a [j]) {
cout<" Collection is not allowed to have a repetition of the positive integer, please input again: ";
Cin> A, [I].
}
}
}
}
}
//set intersection
Void Jiao (int n, m int, int a [], int [] b) {
Int count=0, I, j;
Int c (n + m),
cout<" The intersection of A and B elements are: ";
for(i=0; ifor(j=0; JIf (a [I]==b [j]) {
cout<& lt; A [I] <" ";
The count=+ 1;//the same to count the number of
}
}
}

If (count==0) {
cout<" Empty "& lt; & lt; Endl;
}
The else
cout<& lt; Endl;
}
//set and set, the feeling to write too much trouble...
//while and if some places with mixed up
Void the Union (int n, m int, int a [], int [] b) {
Int I=0, j=0, the count=0, temp.
//USES bubble sort and simplified o set
for(i=0; ifor(j=0; JIf (a [j] & gt; + 1 a [j]) {
Temp=a, [j].
A [j]=a, a + 1 bonus to [j].
A=\ [j + 1];
}
}
}
for(i=0; ifor(j=0; JIf (b [j] & gt; B) [j + 1] {
Temp=b [j];
B=b [j] [j + 1);
B=\ [j + 1];
}
}
}
//check bubble sort
//for (I=0; i//cout<& lt; A, [I].
//}
//for (j=0; J//cout<& lt; B [j];
//}
I=0, j=0;//must have this step
cout<" A, B and set elements are: ";
While ((I!=(n - 1)) & amp; & (j!=(m - 1))) {
If (a [I]==b [j]) {
cout<& lt; A [I] <" ";
i++;
j++;
}

Else if (a [I] cout<& lt; A [I] <" ";
i++;

}

Else if (b [j] cout<& lt; B [j] <" ";
j++;

}
}
While (j==(m - 1) & amp; & i<(n - 1)) {
//consider A: 1 2 3, B: 1 6 and 4 A: 1 2 3, 1 3 6 cases
B:If (b==[m - 1] a [I]) {
cout<& lt; B [j] <" ";
For (I=+ 1; icout<& lt; A [I] <" ";
}
}
Else if (b [m - 1]
cout<& lt; B [j] <" ";
For (; icout<& lt; A [I] <" ";
}
}
While (b/m - 1 & gt; A [I]) {
cout<& lt; A [I] <" ";
i++;
}


}
//application while here, but with the if although trouble but also has given the situations, it is no longer modified
If (I==(n - 1) & amp; & J<(m - 1)) {
If (a/n - 1==b [j]) {
cout<& lt; A [I] <" ";
For (j=j + 1; Jcout<& lt; B [j] <" ";
}
}
Else if (a/n - 1] cout<& lt; A [I] <" ";
For (; Jcout<& lt; B [j] <" ";
}
}
Else if (a/n - 1) & gt; B) [j] {
cout<& lt; B [j] <" ";
j++;
If (a [I]==b [j]) {
cout<& lt; A [I] <" ";
j++;
If (jFor (; Jcout<& lt; B [j] <" ";
}

}

}
Else if (a [I] cout<& lt; A [I] <" ";
For (; Jcout<& lt; B [j] <" ";
}

}

Else if (a [I] & gt; B) [j] {
cout<& lt; B [j] <" ";
For (j=j + 1; JIf (a [I] & gt; B) [j] {
cout<& lt; B [j] <" ";
j++;
}
Else if (a [I] cout<& lt; A [I] <" ";
For (; Jcout<& lt; B [j] <" ";
}
}
Else if (a==b [j] [I]) {
cout<& lt; A [I] <" ";
i++;
j++;
}

}

}

}

}

Else if (I==(n - 1) & amp; & J==(m - 1)) {
For (; iIf (a/n - 1] cout<& lt; A [n - 1] <" "<& lt; B] [m - 1 & lt; <" ";
}
Else if (a==b [n - 1]] [m - 1) {
cout<& lt; A [n - 1] <" ";
}
Else if (a/n - 1) & gt; B] [m - 1) {
cout<& lt; B] [m - 1 & lt; <" "<& lt; A [n - 1] <" ";
}

}

}

cout<& lt; Endl;
}
Void Cha (int n, m int, int a [], int [] b) {
Int I, j, count;
cout<" A - B elements are: ";
for(i=0; iFor (j=0, count=0; J//remember repeat number used to judge whether a [I] currently output
If (a [I]==b [j]) {
Count=count + 1;
}
}
While (count==0) {
cout<& lt; A [I] <" ";
Count=count + 1;
}

}
cout<& lt; Endl;

}
Int main () {
The menu ();
Int num, a_length b_length;
//determine the number of elements in the two collections, to prepare for an array of input
cout<" Please enter the first set the number of elements: ";
Cin> A_length;
Int a [a_length];

cout<" Please enter the second set the number of elements: ";
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related