vendredi 19 août 2016

i am trying to implement vector within vectors for using [mergesort] in c++ half way i am getting errors [on hold]

**i am trying to implement a merge sort on my own by trying to write my own functions in c++**  

 - i wrote a in main function to half vector into elements.
 - in second function i would print vector of vectors.
 - below is my code

i want to implement mergesort with my own functin in c++;

#include <iostream>
#include <vector>
#include <map>
#include <list>
using namespace std;

list<int> adding_sortedlist(); >i want to merge two sorted lists into a new list withthis function also not implemented.
vector<int> merge

sort(vector list); >i have to yet implement this function. void printvector(vector > m); >prototype for function below.

int main(){
    std::vector<int> list;
    > sample vector populated with below elements
    list.push_back(1);
    list.push_back(2);
    list.push_back(3);
    list.push_back(4);
    list.push_back(5);

from here i would calculate my vector length.

    std::vector<int>::iterator f;
    int count =0;
    > to find length of vector i implmented a for loop with iterator 
    for(f=list.begin();f!=list.end();f++){
        count++;
    }

    int list_length=count;  > gives me length of vector.

declared my vector vectors

    std::vector< vector<int> > m; > intialised  vector of vectors like lists of lists in python:)

    > trying to create a new vector for each iteration and adding it to vector

populating with elements with.

    for(int g =0,f=list.begin();f!=list.end() && g <count;f++,g++){
        std::vector<int> t = {*f,};
        m.push_back(t);


    }
    printvector(m); > initialising my printvector function 



}

this functions print vector of vector to screen

void printvector(vector<vector<int>> m){
    std::vector<vector<int>>::iterator d;
    for(d=m.begin();d!=m.end();d++){
        cout << *d << endl;
    }

}

Aucun commentaire:

Enregistrer un commentaire