Click here to Skip to main content
15,867,704 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Exception in CListBox::Addstring Pin
ForNow1-Dec-17 2:53
ForNow1-Dec-17 2:53 
GeneralRe: Exception in CListBox::Addstring Pin
Richard MacCutchan1-Dec-17 3:09
mveRichard MacCutchan1-Dec-17 3:09 
GeneralRe: Exception in CListBox::Addstring Pin
ForNow1-Dec-17 3:13
ForNow1-Dec-17 3:13 
QuestionMatrix not getting initialized Pin
User 1350945030-Nov-17 8:38
professionalUser 1350945030-Nov-17 8:38 
AnswerRe: Matrix not getting initialized Pin
CPallini30-Nov-17 10:37
mveCPallini30-Nov-17 10:37 
GeneralRe: Matrix not getting initialized Pin
User 1350945030-Nov-17 22:00
professionalUser 1350945030-Nov-17 22:00 
GeneralRe: Matrix not getting initialized Pin
CPallini30-Nov-17 22:17
mveCPallini30-Nov-17 22:17 
QuestionHow to find the index of smallest 3 elements in an array Pin
User 1350945030-Nov-17 2:06
professionalUser 1350945030-Nov-17 2:06 
How can we find the index of smallest 3 elements in an array. Below code finds the index of largest 3 elements in an array.

C++
#include <vector>
#include <iostream>

using namespace std;

int main()
{
  double arr[] = {0.2, 1.0, 0.01, 3.0, 0.002, -1.0, -20};
  
  priority_queue < pair<double, int> > pQueue;
  
  for (int i = 0; i < 7; i++) 
  {
    pQueue.push(pair<double, int>(arr[i], i));
  }
  
  int k = 3; // number of indices we need
  
  for (int i = 0; i < k; ++i) 
  {
    int ki = pQueue.top().second;
    cout << ki << " ";
    pQueue.pop();
  }
  
}


modified 29-Jan-21 21:01pm.

AnswerRe: How to find the index of smallest 3 elements in an array Pin
Jochen Arndt30-Nov-17 2:24
professionalJochen Arndt30-Nov-17 2:24 
GeneralRe: How to find the index of smallest 3 elements in an array Pin
User 1350945030-Nov-17 2:32
professionalUser 1350945030-Nov-17 2:32 
GeneralRe: How to find the index of smallest 3 elements in an array Pin
Jochen Arndt30-Nov-17 2:54
professionalJochen Arndt30-Nov-17 2:54 
GeneralRe: How to find the index of smallest 3 elements in an array Pin
User 1350945030-Nov-17 4:56
professionalUser 1350945030-Nov-17 4:56 
QuestionPrecision in C Pin
Anonygeeker29-Nov-17 18:13
Anonygeeker29-Nov-17 18:13 
AnswerRe: Precision in C Pin
Peter_in_278029-Nov-17 19:05
professionalPeter_in_278029-Nov-17 19:05 
AnswerRe: Precision in C Pin
Rick York29-Nov-17 19:51
mveRick York29-Nov-17 19:51 
AnswerRe: Precision in C Pin
Richard MacCutchan29-Nov-17 21:40
mveRichard MacCutchan29-Nov-17 21:40 
SuggestionRe: Precision in C Pin
David Crow30-Nov-17 5:20
David Crow30-Nov-17 5:20 
Questionwhat is contained in iostream and std Pin
Anonygeeker28-Nov-17 23:21
Anonygeeker28-Nov-17 23:21 
AnswerRe: what is contained in iostream and std Pin
CPallini29-Nov-17 0:33
mveCPallini29-Nov-17 0:33 
GeneralRe: what is contained in iostream and std Pin
Anonygeeker29-Nov-17 1:16
Anonygeeker29-Nov-17 1:16 
GeneralRe: what is contained in iostream and std Pin
CPallini29-Nov-17 1:23
mveCPallini29-Nov-17 1:23 
AnswerRe: what is contained in iostream and std Pin
jschell29-Nov-17 12:39
jschell29-Nov-17 12:39 
QuestionC++ cout in header file error - ‘cout’ was not declared in this scope Pin
Vaclav_27-Nov-17 14:23
Vaclav_27-Nov-17 14:23 
QuestionRe: C++ cout in header file error - ‘cout’ was not declared in this scope Pin
David Crow27-Nov-17 16:47
David Crow27-Nov-17 16:47 
AnswerRe: C++ cout in header file error - ‘cout’ was not declared in this scope Pin
CPallini27-Nov-17 21:31
mveCPallini27-Nov-17 21:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.