Archive for the ‘C plus plus’ Category

Control structures and statements in C and C++

Control structures form the basic entities of a “structured programming language“. We all know languages like C/C++ or Java are all structured programming languages. Control structures are used to alter the flow of execution of the program.  Why do we need to alter the program flow ? The reason is “decision making“! In life, we may be given with a set of option like doing “Electronics” or “Computer science”. We do make a decision by analyzing certain conditions (like our personal interest, scope of job opportunities etc). With the decision we make, we alter the flow of our life’s direction….

Read More

Quick Sorting algorithm with example code in C/C++/Java languages

We have seen 3 simple sorting algorithms already 1) Bubble Sorting 2) Selection Sorting and finally Insertion sorting. All these algorithms were so simple to understand and were easy to implement as a program in C/C++ or even Java. But at the same time all 3 of them were too inefficient.  Their execution time was of the order of n*n, where n is the number of elements to be sorted. In practice, these simple sorting algorithms are seldom used.  Quick sort is an improved sorting algorithm developed by Tony Hoare (C.A.R Hoare) in 1960, at the  age of 26, while…

Read More

Insertion sorting algorithm with example in C/C++/Java languages

So far we have seen 2 sorting algorithms:- 1) Bubble sorting and 2) Selection sorting. Now in this article, we are analyzing insertion sort algorithm with its example code suitable for C/C++/Java programming languages. I recommend you go through above articles of Bubble sorting and Selection sorting before reading further.  Insertion sorting algorithm sorts one element at a time. It begins by sorting the first 2 elements in order. In the next step, it takes the third element and compares it against the first two sorted elements. Exchanges are made if necessary and the 3 elements will be sorted with respect to…

Read More

Selection Sort in C/C++/Java programming languages

In the previous article, we have analysed Bubble sort algorithm and it’s implementation in C programs. In this article we are going to see another sorting algorithm, named, Selection sorting. Just like “Bubble sort”, selection sort is also considered as an inefficient sorting algorithm. If you are curious to know the reason for this, please read the article about Bubble sort carefully. The number of comparisons involved in an average bubble sort is 0.5*(n*n-n). Same is the index for Selection sort too. Note:- Since the algorithm is implemented with the help of 2 FOR loops only, it can be used…

Read More

Difference between Procedure Oriented(POP) and Object Oriented Programming(OOP)

We all know there exist 2 approaches to write a program – 1) Procedure oriented programming (POP) and 2) Object oriented programming (OOP). You can write a program in either way but there are notable differences between both approaches. These 2 approaches are the result of software development evolution over many decades. Since the invention of computer, many approaches and methods have been tried to write a program. It includes methods like a) Top-Down programming b) Bottom-Up programming c) Modular programming  d) Structured programming etc. The basic purpose or the basic aim of all these methods were same – “to…

Read More

What is C++ ? An Introduction to programming with C++

I am beginning a series of articles about C++ programming language. So lets begin with a simple C++ program as shown below. #include int main() { cout

Read More

Bubble Sorting with example in C/C++/Java

Bubble sorting is one of the simplest sorting algorithm that we can use to sort an array or a structure. Though it is so simple to implement in a C program, bubble sort is also considered as an inefficient sorting algorithm. Bubble sort comes handy in cases where the total number of elements to be sorted is so small (may be in the 100′s range). When the data size is large/huge bubble sort is seldom used in practical programming world. Let’s analyse bubble sort algorithm in detail by implementing it as a C program.  Note:- Since the algorithm is implemented with the help of 2 FOR…

Read More