|
I have 20 names and there makes stored in a map. My requirement is to get hghest marks of top 10 studens.
please let me know the sorting algorithim to find that out.
Thanks in Advance
|
|
|
|
|
find out how value_compare(), it will compare the values that way you will know which key comes first
|
|
|
|
|
|
You may try to implement yourself a simple sorting algorithm, like, for instance [^], it maybe an interesting experience.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
If you used this:
std::map<MarkType, NameType> marksAndStudents;
(where MarkType is the type you use for a students marks and NameType is the type you use for a students name, then *rbegin() points at the student with the highest mark - try this:
std::map<int, std::string> s;
s.insert(std::make_pair(10, "10"));
s.insert(std::make_pair(20, "20"));
s.insert(std::make_pair(30, "30"));
s.insert(std::make_pair(40, "40"));
s.insert(std::make_pair(50, "50"));
s.insert(std::make_pair(60, "60"));
s.insert(std::make_pair(70, "70"));
s.insert(std::make_pair(80, "80"));
s.insert(std::make_pair(90, "90"));
s.insert(std::make_pair(100, "100"));
s.insert(std::make_pair(110, "110"));
s.insert(std::make_pair(120, "120"));
std::map<int, std::string>::const_reverse_iterator it = s.rbegin();
for (int i=0;i<10;++i)
{
std::cout << it->second << std::endl;++it;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi
I wrote a code that has multiple threads, each thread has to run independent of another and complete at different times. I tried using the sleep() function to delay execution for some seconds but the program terminates while threads are still sleeping. I also tried using usleep() function, its works fine with small parameters but behave the same as sleep() with large parameters.
Is there anyway that I can delay program termination until my threads are awake and have completed there task?
OR
Is there a better way of delaying the threads other than using sleep() and usleep()?
Thanx
|
|
|
|
|
Call pthread_join() [^] for each thread you have created before your main program exits.
|
|
|
|
|
thanx,
I do pthread_join() call for all my threads but the sleeping ones do not get there. From the sample file, I have to create about five thread, only two are required to delay. The delayed threads do not get to the pthread_join() call but the other three get there. Seems the programs continues running as if there are no sleeping threads.
|
|
|
|
|
Hi All,
I have .Prn file which was generated out of PCL printer.I need to find a string in that file and then I have to replace it with another string.
Iam able to do it by using stream writer,streamreader,Binary reader,binary writer and file streams.
But if gave a print(LPR)for it, it get failed and giving me syntax error as Illegal tag.
If I print original file it is printing very well.
I came to know that while writing it has lost some of its originality ,so it was failed
Please help me
Thanks in advance
|
|
|
|
|
It sounds like you've done more than just changing the string. I don't know about the format, but maybe just before the string is a tag describing the string and its length?
Try replacing just one character in the string - or maybe make one already there be in upper instead of lower case.
Yours experimentally,
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Hi,
Thanks for the reply,
The original file size is like 16k, after the editing it becoming as 22k..
more over it is not normal file,It is a file generated by PCL printer.
So may be during the conversion it is losing printer supported font.
so that's the reason printer cannot understand the file(after editing)to print.so it gives syntax error as Kernel and Illegal tag error.
I have no clues to overcome this problem
kindly help me
|
|
|
|
|
If the size is changing from 16k to 22k, you're doing a lot more than swapping a string!
Just try with baby steps. Tweak one little bit, test, tweak a bigger bit, test, and so on.
I've no idea about the format either - this is just general advice.
It's worth jumping in the deep end sometimes, but other times you just dip one toe in the water.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Hi all
I am having a C++ class and in that some functions are also there.One variable i want to use in a function only.So i can declare it inside that function or as a member variable.
Variables declared in a function will be saved on the stack but what about member variables.
Which way should be more efficient.
Can anybody help me to show some good articles in good programming practices.
Thanks and regards
Deepu
|
|
|
|
|
Where member variables are stored will depend upon how the class is instantiated.
If an object of the class is created on the stack, the member variables will also reside on the stack.
If the object is created on the heap, the member variables will also reside on the heap.
If a variable is used only within a function, you should declare it within that function itself.
And if you want the value retained across function calls, then declare it static.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
|
Hai !
There is a global byte pointer in my apllication, I donot know its size,
is there any inbuilt function in MFC to know its length similiar to GetLength () for strings !!
thanks!
|
|
|
|
|
If the pointer points to a NULL terminated string you can use strlen .
If it points to some binary data, there is no way to get the length.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Does it point at a dinamically allocated block? If you allocated it with malloc, you can try to use _msize[^] to get the size.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Hi All. i ve a small doubt.
Suppose i ve a class like
class A
{
public:
void F();
}
class B:public A
{
public:
virtual void F();
}
My requirment is that whenever i'll call F() of class B it should execute F() of B followed by F() of A
i wrote like
vod B::F()
{
/// doing sm thing
A::F();
}
IS this correct?
is theree any other way to do this?
Regards
Phillip
Regards
Phillip
|
|
|
|
|
You're doing it just fine. One small question: why is F virtual in B but not in its base A ?
Steve
|
|
|
|
|
Hi. Thanks for the reply.
Actually i faced this question in one interview. I gave same answer but the interviwer was unhappy with the answer. she told me it c'd b done in better way.
Regards
Phillip
|
|
|
|
|
Perfect!!!
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
In case if you are trying for chain of events, I'd suggest the below one. I just typed it for fun, so don't look at the convections
class base
{
public:
base* m_p;
std::string m_st;
base(std::string st):m_st(st),m_p(NULL)
{
}
void setRoot(base* p)
{
m_p = p;
}
void execute()
{
cout<<m_st.c_str()<<endl;
if(m_p)
{ m_p->execute();}
}
};
You don't need to derive & create a separate classe, just try this:
base b("Code");
base b2("Project");
base b3("Bob");
b2.setRoot(&b);
b3.setRoot(&b2);
b3.execute();
might look like the responsibility pattern, but not exactly, it's Vunic's custom patter .
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
I want the code for soundex algorithm which is used for the spell checking compatible for front end in ASP and back end in C#
|
|
|
|
|
Well, what to say...Good luck and enjoy the experience.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|