Showing posts with label Data Structures. Show all posts
Showing posts with label Data Structures. Show all posts

Monday, June 24, 2013

Stacks and C++ Program | Data Structures And Algorithms

Stacks is a Data Structure in computer and a Abstract Data Type. Abstract Data Types (ADT's) is defined as a mathematical model of the data objects that make up a data type as well as the functions that operate on these objects.

Example: Int type defining a variable a and b and then adding
You would get the same result as you would by adding two numbers mathematically

Stacks is a container of objects that are inserted and removed using Last-in-first-out principle. Objects can be inserted at any time, but only the last (the most-recently added) object can be removed.

Pushing: Inseting an item.
Popping: removing an item.

Stacks are supported with the following methods Four Main Methods.

Monday, June 10, 2013

C++ Program to Solve the Quadratic Equation

Welcome to GSinghCodes. This is the first post on this Blog, hopefully I will continue to add more as time progresses.

Today I will explain the C Plus Plus Program which Solves the Quadratic Equation. Before we get started we need to look at the Quadratic Equations. "Standard Form" of a Quadratic Equation is ax2 + bx + c = 0, where a b and c are known, a cannot be zero and x is the unknown variable we have to find. To solve the equation we can use the quadratic formula:
Their are three types of answers you can get with the quadratic formula, Two real solutions (If the discriminant (the part inside the square root) is greater than zero) , No Real Solution (If the discriminant is strictly less than zero and One real solution(If the discriminant is equal to zero). To See Examples Click Here.

Examples To Test
 0x^2 + 0x + 0 = 0 Answer = "All Solutions"
 0x^2 + 0x + 1 = 0 Answer = "No Solutions"
 0x^2 + 2x + 1 = 0 Answer = -1/2
 1x^2 + 2x + 1 = 0 Answer = "Duplicate Solution" = -1
 1x^2 + 4x + 1 = 0 Answer = "two solutions" = d = 3.464 1st root = -0.267 | 2nd root = -3.73

C Plus Plus Program to Solve the Quadratic Equation