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;

}

Recommended Answers

All 4 Replies

sort the vector inside the sortPrint function and then print it?

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.