Last time, we discussed a sorting technique known as insertion sort. It is a very good sorting procedure and the simplest sorting algorithm for short lists and small amount of data. For larger lists, it’s running time increases exponentially which renders it inefficient. A number of variations have also been introduced to insertion sort, some of which are more efficient and some are equally good. Shell sort and Gnome Sort are two such variations. I prefer Gnome Sort so I will explain it to you in this article.
We have learnt that Templates in C are a very powerful feature. They constitute the concept of Generic Programming or Type Independent Programming. Last time, we saw templates that have one parameter or one generic type. They have the limitation that only one type of data type can be processed at a time. To solve that problem, we use templates with more than one type of parameters. Such multiple type templates allow more than one type of data types to be process at once.
For Novice and Beginners, C seems a very difficult and challenging language to learn. I won’t say that this is incorrect in entirety though constant practice and hard work makes it easier to code in C .
Here I shall briefly describe some of the Online Resources which I have used personally and found extremely useful. These include resources for learning, debugging to problem solving.
C++ is a very powerful and fast language. One potential danger because of this is the ability of language to call methods and convert data into other types automatically without asking the programmer. So the programmer has an added responsibility of keeping an eye on the compiler and watch out for all such errors. One such common problem is the implicit conversion through a constructor. To avoid that, we use an explicit constructor in C++. Let us see a sample code for that and then I shall explain to you what actually happens.
Up till now we have overloaded assignment operator and then the addition operator. One another operator which we quite frequently use in our program and thus need to redefine for ourselves is the indexing operator ([ ]). Indexing operator in in fact used to dereference a given index of the array. After overloading indexing operator, we can directly dereference the object for our particular index. Let us see how we can efficiently do this.