marq

Dr. Charles Simonyi is the Father of Modern Microsoft Excel                                           JavaScript was originally developed by Brendan Eich of Netscape under the name Mocha, later LiveScript, and finally renamed to JavaScript.                                           The word "Biology" is firstly used by Lamarck and Treviranus                                           Hippocrates (460-370 bc) is known as father of medicine.                                           Galene, 130-200 is known as father of Experimental Physology                                           Aristotle (384-322 BC) is known as Father of Zoology because he wrote the construction and behavior of different animals in his book "Historia animalium"                                           Theophrastus(370-285 BC) is known as father of Botany because he wrote about 500 different plants in his book "Historia Plantarum".                                           John Resig is known as Father of Jquery -                                          HTML is a markup language which is use to design web pages. It was invented in 1990 by Tim Berners-Lee.                                                                The Google was founded by Larry Page and Sergey Brin.                                                                Rasmus Lerdorf was the original creator of PHP. It was first released in 1995.                                                               Facebook was founded by Mark Zuckerberg                                                               Bjarne Stroustrup, creator of C++.                                                                Dennis Ritchie creator of C                                                                                                                              James Gosling, also known as the "Father of Java"                                          At 11.44%, Bihar is India's fastest growing state                                          Father of HTML -Tim Berners Lee                                          orkut was created by Orkut Büyükkökten, a Turkish software engineer                    Photoshop: It came about after Thomas Knoll, a PhD student at the University of Michigan created a program to display grayscale images on a monochrome monitor which at the time was called 'Display'.

Stack

The stack is one of the most important data structures in computer science. A stack is a last-in first-out data structure (LIFO). 

Stack Overview

Stack follows the rule of last in first out rule. Mainly two action are performed by stack one is push and other is pop. The last thing which we placed or push on stack is the first thing we can get when we pop. A stack is a list of element with insertion and deletion at one end only.
Below depict the operational behaviors of stack. You can see one thing that push and pop operation is done at one end and whatever element we keep on stack is shown at the top of stack.

===================================================================




Push and Pop operation of stack.


This tutorial demonstrate the push and pop operation of stack using array.

Description:

In this tutorial of data-structure you will see push and pop operation of stack. In the previous tutorial is clearly explained the push pop operation. The drawback of implementing stack is that the size of stack is fixed it cannot grow or shrink.

Code:

#include <stdio.h>
#include <stdlib.h>
void push(int stack[], int *top, int value)
{
 if(*top < 4 )
  {
 *top = *top + 1;
 stack[*top] = value;
 printf("\nStack element should be less than four\n");
 }
 else
 {
 printf("\nThe stack is full can not push a  value\n");
 exit(0);
 }
}
void pop(int stack[], int *top, int * value)
{
 if(*top >= 0 )
 {
  *value = stack[*top];
  *top = *top - 1;
 }
 else
 {
 printf("\nThe stack is empty can not pop a  value\n");
 exit(0);
 }
}
 void main()
 {
 int stack[4];
 int top = 0;
 int n,value;
 do
 {
   do
   {
  printf("\nEnter the element to be pushed\n");
  scanf("%d",&value);
  push(stack,&top,value);
  printf("\nEnter 1 to continue and other key to pop\n");
  scanf("%d",&n);
  printf("");
   }    while(n == 1);
    printf("\nEnter 1 to pop an element\n");
    scanf("%d",&n);
    while( n == 1)
   {
   pop(stack,&top,&value);
   printf("\nThe value poped is %d",value);
   printf("\nEnter 1 to pop an element\n");
   scanf("%d",&n);
   }
   printf("\nEnter 1 to continue and other key to push\n");
   scanf("%d",&n);
 } while(n == 1);
}

Output:



=================================================================


Push and Pop operation of stack using linked list.




The fundamental operation of stack is push and pop. The term push is use to place some data element into the stack and pop is use to remove some data element from the stack. 

Description:

In this tutorial of data-structure you will see push and pop operation of stack using linked list. In the previous tutorial the stack operation in done using array.

Code:

# include <stdio.h>
# include <stdlib.h>
struct node
{
int data;
struct node *link;
};
struct node *push(struct node *p , int value)
{
 struct node *temp;
 temp=(struct node *)malloc(sizeof(struct node));
 if(temp==NULL)
 {
  printf("No Memory available\n");
  exit(0);
 }
  temp->data = value;
  temp->link = p;
  p = temp;
  return(p);
 }

struct node *pop(struct node *p , int *value)
{
 struct node *temp;
 if(p==NULL)
 {
 printf(" The stack is empty and cannot pop element\n");
        exit(0);
 }
  *value = p->data;
 temp = p;
 p = p->link;
 free(temp);
 return(p);
 }

void main()
{
struct node *top = NULL;
int n,value;
do
{
  do
  {
 printf("Enter the element to be pushed in stack\n");
 scanf("%d",&value);
 top = push(top,value);
 printf("Enter 1 to continue\n");
 scanf("%d",&n);
 } while(n == 1);

  printf("Enter 1 to pop an element from stack\n");
  scanf("%d",&n);
  while( n == 1)
 {
 top = pop(top,&value);
 printf("The value poped is %d\n",value);
 printf("Enter 1 to pop an element and other to push\n");
 scanf("%d",&n);
 }
  printf("Enter 1 to continue\n");
  scanf("%d",&n);
} while(n == 1);
}

Output:



No comments:

Post a Comment