Skip to main content

Posts

Queue and its Implementation using C++

Queue:  A queue is a container that implements the first in first out protocol. That means that the only accessible object in the container is the one among them that was inserted first. A good analogy is a group of people waiting in line of a ticket. The next one admitted is the person in the line who got here ahead of everyone else.   Common operations of queue on C++ are bool empty() Returns True if the queue is empty, and False otherwise. T & front() Returns a reference to the value at the front of a non-empty queue. There is also a constant version of this function,  const T & front() . void pop() Removes the item at the front of a non-empty queue. void push(const T &foo) Inserts the argument foo at the back of the queue. size_type size() Returns the total number of elements in the queue. Example: Stuck Implementation on C++  #include<iostream> #include<queue> using namespace std; template <class T> void print (const queue...

Stacks and its Implementation using C++

Stuck: Stack is a last in, first out (LIFO) abstract data type and data structure. It is a container that implements the last in first out (LIFO) Protocol. That means that the only accessible object in the container is the last one among them that was inserted. A stack of book is a good analogy: you can’t read any in the stack without first removing the books that are stacked on top of it. It has three fundamental operations: push, pop and stack top. When we using stack, we need a header file called stack. Example: Stuck Implementation on C++ #include<stack> using namespace std; int main(){ stack<string> s; s.push("Linux"); s.push("JAVA"); s.push("Oracle"); s.push("PHP"); cout<< "s.size() = " << s.size() << "\n"; while(!s.empty()){ cout << "s.top() = " <<s.top() <<"\n";    s.pop(); } cout<< "s.size() = " << s.s...

Absolute value and Floating-point absolute value function in C Programming Language

Absolute value function in C Programming Language is abs(i), Its return the absolute valu of i. where  i  is any positive or negative  number. It is integer type function. The include file of abs(i) is stslib.h Observe under program: #include<stdio.h> #include<stdlib.h> int main(void) { int a; scanf("%d",&a); printf("%d",abs(a)); } Here I use a integer number. Input it by scanf and print the Absolute value by abs() function. Floating-point Absolute value function in C Programming Language is fabs(i), Its return the absolute valu of i. where  i  is any positive or negative  Floating-point number. It is double integer type function. The include file of fabs(i) is math.h Observe under program: #include<stdio.h> #include<stdlib.h>  int main(void) { float a; scanf("%f",&a); printf("%.2f",fabs(a)); } Here I use a integer number. Input it by scanf and print the Floating-point Absolute value b...

Variables in C Programming Language

Variables:   A variable is a named location in memory that is used to hold a value that can modified by a program. The general form of a variable declaration is Variable-type variable –name By the declaration of variables, there are three type Variables; 1.        Loacal 2.        Formal 3.        Global Local Variable:   If a variable declared inside a function called Local Variable. You may called it also Automatic Variable. Condition: 1.        It works in a function or a code block, if you exit form function the local variable destroyed.

Operator in C Programming Language.

Operator:  C has many built in Operator. There are four main operators in c Programming Language. Arithmetic Operator Relational Operator Logical Operator   Bitwise Operator But there are some special Operators, such as Assignment Operator Conditional Operator Unary Operator etc. General form Assignment Operator:   The Operator who assigns a value or expression called Assignment Operator General form of Assignment Operator Variable_name= expression  Single Assignment: If we assign only one variable to a value is called Single Assignment. Example:   X=5; Y=z; etc. Multiple Assignments: If we assign many variable to a value is called Multiple Assignment. Example: x=y=z=5; A=b=c=Pi; etc. Compound Assignment: If we assign a statement to a value is called Compound Assignment. Example: x=y+5; x=x+5; it also can be written as x+=5; x=x-5; it also can be written as x-=5; etc.

Hexadecimal and Octal Constant in C Programming

Octal:   The number system based on 8 is called octal and uses the digits 0 through 7. In octal, the number 15 is the same as 13 in decimal. Hexadecimal:   The base 16 number system is called hexadecimal and uses the digits 0 through 9 plus the letters A through F, which stand for 10, 11, 12, 13, 14, and 15, respectively. For example, the hexadecimal number A is 10 in decimal. It is sometimes more easier to use a number system based on 8 or 16 rather than 10. Because these two number systems are used frequently, C allows usto specify integer constants in hexadecimal or octal instead of decimal. A hexadecimal constant must consist of a Ox followed by the constant in hexadecimal form. An octal constant begins with a 0. Here are two examples: int hex = 0x40;       in Decimal 64 int oct = 040;          in Decimal 32

Assignment Operator

Assignment Operator :   The Operator who assigns a value or expression called Assignment Operator General form of Assignment Operator Variable_name= expression  Single Assignment: If we assign only one variable to a value is called Single Assignment. Example:   X=5; Y=z; etc. Multiple Assignments: If we assign many variable to a value is called Multiple Assignment. Example: x=y=z=5; A=b=c=Pi; etc. Compound Assignment: If we assign a statement to a value is called Compound Assignment. Example: x=y+5; x=x+5; it also can be written as x+=5; x=x-5; it also can be written as x-=5; etc.