Example #1
0
int KthMin::findKthMin(IDoubleList03 * data, int k)
{
	IDoubleNode03* head = data->getHead();
	std::vector<int> vec;
	while (head)
	{
		vec.push_back(head->getValue());
		head = head->getNext();
	}
	//for (size_t i = 0; i < vec.size(); i++) {
	// cout << i << "th, num is " << vec[i] << endl;
	//}

	HeapSort sorter;
	sorter.sort(vec);
	return vec[k];

	int index = 0;
	int min = -1;
	k += 1;
	for (size_t i = 0; i < k; ++i) {
		if (vec.empty()) return min;
		min = vec[0];
		for (size_t j = 0; j < vec.size(); ++j) {
			if (vec[j] < min) {
				min = vec[j];
				index = j;
			}
		}
		vec.erase(vec.begin() + index);
	}
	
	return min;
}
Example #2
0
int main(){
        int N,number;
        cin>>N;
        HeapSort hs;
        for (int i = 0; i < N; i++)
        {   
                cin>>number;
                hs.insert(number);
        }
        hs.sort();
        for (int i = 0; i < N; i++)
        {
                if(i){
                        cout<<' ';
                }
                cout<<hs[i];
        }
        cout<<endl;
        return 0;

}