-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVECTOR.cpp
63 lines (53 loc) · 1.38 KB
/
VECTOR.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <fstream>
#include <numeric>
#include <vector>
#include <algorithm>
#include "VECTOR.h"
using namespace std;
//VECTOR OBJECT
VectorObj::VectorObj(int len) : len(len) {
swaps = 0;
for (int i = 0; i < len; i++) {
vect.push_back(rand() % 101); // Creating a random vector of integers
}
}
VectorObj::~VectorObj() {}
void VectorObj::swapIndex(int i, int j) {
if (i != j) { // Check to prevent unnecessary swaps
swap(vect[i], vect[j]);
swaps++; // Keeping track of the swaps
};
};
//NAMED VECTOR OBJECT
NamedVectorObj::NamedVectorObj(string name, int len) : VectorObj(len), name(name) {}
NamedVectorObj::~NamedVectorObj() {
cout << "peace out i'm outta here :)" << endl;
}
void NamedVectorObj::printData(NamedVectorObj& vect) {
for (int i = 0; i < vect.getSize(); i++) {
cout << vect.vect[i];
if (i < vect.getSize() - 1) {
cout << ", ";
}
}
cout << endl;
}
bool NamedVectorObj::isSorted(NamedVectorObj& vect) {
bool ans;
ans = is_sorted(vect.vect.begin(), vect.vect.end());
return ans;
}
ostream& operator<<(ostream& os, NamedVectorObj& vect) {
os << "Name of sort: " << vect.name << endl << "Swaps needed: " << vect.swaps << endl << "Sorted vector: ";
for (int i = 0; i < vect.vect.size(); i++) {
os << vect.vect[i];
if (i < vect.vect.size() - 1) {
cout << ", ";
}
}
os << endl;
return os;
}