I'm calling sortprint but how can I Implement it? I also want to implement a the sort function.


I highlighted some of the things in red.

#include <iostream>
#include <vector>
using namespace std; 
    
void sortPrint( const vector<int>& v);
int main()

{

	vector<int> v;
	vector<int>::iterator iter;
	int num;

	cout <<"Enter the number you want to be sort and print than push ctrl z to end it. "<<endl;

	while(cin>>num)
     {

		v.push_back(num);

	}
	cout<<"The numbers you enter are :";
    sortPrint(v);
	cout<<endl;
 
    cout<<"The numbers in ascending order is :"<<endl;
    sort (v.begin(), v.end());
    for (iter=v.begin(); iter!=v.end(); ++iter) 
    {
        cout<< *iter << " ";
    }
    cout<<endl<<endl;
	
    system ("pause");
	return 0; 

}


void sortPrint( const vector<int>& v)
{

	for(int i=0; i<v.size(); ++i)
    {
		cout << v[i] << " ";
    }
	cout << endl;

}

i want to implement the sort and sortprint functions. I'm calling sortprint know but how can i implement it.

should sortPrint first sort the vector and then print it out?

Do something like this :

void sortPrint(std::vector<int> v){
 //sort v using your sorting algorithm?
 //print out each element in v;
}

should sortPrint first sort the vector and then print it out?

Do something like this :

void sortPrint(std::vector<int> v){
 //sort v using your sorting algorithm?
 //print out each element in v;
}

Thanks!

This article has been dead for over six months. Start a new discussion instead.