0% found this document useful (0 votes)
33 views3 pages

Assignment Programming 9

Uploaded by

wwdjjscg5j
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Assignment Programming 9

Uploaded by

wwdjjscg5j
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS112

Dr.Awad Hasballah
AL.Mahinda Mahmoud
Faculty of Computer Science & Technology.

Assignment 9
Name: Mariam Ahmed Atwa
Group: B
ID: 20220665
Question no.9:
#include <iostream>
#include <vector>

using namespace std;

vector<int> merge_sorted(vector<int> a, vector<int> b) {


vector<int> result;
int i = 0;
int j = 0;
while (i < a.size() && j < b.size()) {
if (a[i] < b[j]) {
result.push_back(a[i]);
i++;
}
else {
result.push_back(b[j]);
j++;
}
}

while (i < a.size()) {


result.push_back(a[i]);
i++;
}

while (j < b.size()) {


result.push_back(b[j]);
j++;
}

return result;
}

int main() {

vector<int> a = { 1, 4, 9, 16 };
vector<int> b = { 4, 7, 9, 9, 11 };

vector<int> result = merge_sorted(a, b);

for (int i = 0; i < result.size(); i++) {


cout << result[i] << " ";
}

cout << endl;

return 0;
}
Question no.10:
#include <iostream>

using namespace std;


void sort2(double* p1, double* p2) {

if (p1 == 0 || p2 == 0) {
return;
}
double temp = *p1;
*p1 = *p2;
*p2 = temp;
}

int main() {

double x, y;
cin >> x;
cin >> y;

sort2(&x, &y);

if (x <= y) {
cout << "true" << endl;
}
else {
cout << "false" << endl;
}

return 0;
}
Question no.11:

You might also like