Skip to content

Instantly share code, notes, and snippets.

Created December 11, 2013 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7903024 to your computer and use it in GitHub Desktop.
Save anonymous/7903024 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
//Function: Print_Array
void Print_Array(const vector<int>& Arr, int size){
cout << "Contents of the array" << endl;
for(int i = 0; i < size; i++){
cout << Arr[i] << " ";
}
cout << endl;
}
//Function: swap
void swap(int& a, int & b){
int temp=a;
a=b;
b=temp;
}
//Function: vector_sort
void vector_sort(vector<int>& Arr, vector<int> & vect){
int max_size=-1;
for(int j=0; j<Arr.size(); j++){
for(int i=0; i<Arr.size()-1; i++){
if(Arr[i+1]>Arr[i]){
swap(Arr[i+1],Arr[i]);
}
}
}
int num_size=-1;
for(int m=0; m<vect.size(); m++){
for(int n=0; n<vect.size()-1; n++){
if(vect[n+1]<vect[n]){
swap(vect[n+1], vect[n]);
}
}
}
}
int main(){
//First, we should declare the vectors to get them out of the way.
vector<int> start_time;
vector<int> end_time;
vector<int> schedule;
int num_act;
cout << "How many activities are there scheduled for today?";
cin >> num_act;
int start;
int end;
//to keep the while loop set, we need to keep count of how many enteries there are, or it will be infinite.
int act_entered=0;
while(act_entered<num_act){
cout << "Enter the start time:";
cin >> start;
start_time.push_back(start);
cout << "Enter the end time:";
cin >> end;
end_time.push_back(end);
act_entered++;
}
int cur_time=0;
for(int k=0; k<num_act; k++){
if(end_time[k]<=start_time[k+1]){
cur_time=end_time[k];
}
}
Print_Array(start_time, num_act);
vector_sort(start_time, end_time);
Print_Array(end_time, num_act);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment