Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>
#include "Data.h"

using namespace std;


Data::Data()
{
x=0;
y=0.0;
}

Data::Data(int a, float b)
{
x=a;
y=b;
}
float Data::getY()
{
return y;
}
int Data::getX()
{
return x;
}
void Data::setX(int a)
{
x=a;
}
void Data::setY(float a)
{
y=a;
}

28 changes: 28 additions & 0 deletions Data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef DATA_H
#define DATA_H

#include <iostream>
#include <vector>

using namespace std;

class Data
{
private:

int x;
float y;

public:

Data();
Data(int a, float b);
float getY();
int getX();
void setX(int a);
void setY(float a);


};

#endif
Binary file added hellogit,out
Binary file not shown.
113 changes: 113 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include <iostream>
#include <vector>
#include "Data.h"

using namespace std;

void print (auto A)
{
for (auto a : A)
cout << a << " ";

cout<<endl;
}

void printClass (auto A)
{
for (auto a : A)
cout << a.getX() << " "<< a.getY() << " ";

cout<<endl<<endl;
}

void insertionSort (auto& D)
{
for (int i=1; i < D.size(); i++)
{
int j=i;
while (j > 0 and D[j] < D[j-1])
{
swap (D[j], D[j-1]);
j--;
}
print(D);

}
}

void insertionSortClass (auto& D)
{
for (int i=1; i < D.size(); i++)
{
int j=i;
while (j > 0 and D[j].getX() < D[j-1].getX())
{
swap (D[j], D[j-1]);
j--;
}
printClass(D);

}
}

int main()


{

vector<int> v1;
vector<int> v2={22,8,7,9,45};
v1.push_back(17);

vector <int> w = {7, 6, 5, 4, 3, 2};

insertionSort(w);

for (auto i:w)
{
cout << i << " ";
}


cout <<endl<<endl<<endl;

cout << "V2 has " << v2.size() << " elements. They are:" << endl<<endl;

for (auto x:v2)
{
cout << x << endl;
}

cout << endl;

Data d0;
Data d1 = {7,24.83};
d0.setX(15);
d0.setY(3.14);

vector<Data> v;
v.push_back( {7,21.01} );
Data d;
v.push_back(d);
d.setX(6);
d.setY(12.10);
v.push_back(d);
d.setX(5);
d.setY(6.12);
v.push_back(d);

cout <<endl<<"The Vector V of type Data contains: "<< endl<<endl;



for (auto a:v)
{
cout << a.getX() << " ";
cout << a.getY() << endl<< endl;

}

insertionSortClass(v);
return 0;

}