Monday, December 16, 2013

Array




#include<stdio.h>
#include<conio.h>
 void main()
 {
int arr[10];
int i,j;
int temp;
int count;

for(i=0;i<10;i++)
{
printf(" Enter value= ");
scanf("%d",&arr[i]);
}
printf("\nUnsorted array -->\n");
for(i=0;i<10;i++)
printf("%d\t",arr[i]);

for(i=0;i<10;i++)
{
for(j=0;j<10-i;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("\nSorted array -->\n");
for(i=0;i<10;i++)
printf("%d\t",arr[i]);

i=0;
while(i<10)
{
j=i;
count=1;
while(arr[j]==arr[j+1])
{
count++;
j++;
}
printf("\nFrequency of %d= %d",arr[j],count);
i=i+count;
}
getch();
 }

ARRAY

// WAP TO INPUT A NO. AND SEARCH THAT NO. IN 10 ELEMENTS ARRAY.

#include<stdio.h>
#include<conio.h>
 void main()
 {
int arr[10];
int i;
int sd;

clrscr();

for(i=0;i<10;i++)
{
printf(" Enter value= ");
scanf("%d",&arr[i]);
}
printf("\nGi");
for(i=0;i<10;i++)
printf("%d",arr[i]);


 }

SORTING

WAP TO ENTER 10 NO.S IN AN ARRAY AND ARRANGE THAT NO.S IN ASCENDING ORDER.
    (2nd METHOD- SELECTION SORT) */


#include<stdio.h>
#include<conio.h>
 void main()
 {
int arr[10];
int i,j;
int temp;
int small,pos;

clrscr();

for(i=0;i<10;i++)
{
printf(" Enter value= ");
scanf("%d",&arr[i]);
}
printf("\nUnsorted array -->\n");
for(i=0;i<10;i++)
printf("%d\t",arr[i]);

for(i=0;i<10;i++)
{
small=arr[i];
for(j=i;j<10;j++)
{
if(small>arr[j])
{
small=arr[j];
pos=j;
}
}
temp=arr[i];
arr[i]=arr[pos];
arr[pos]=temp;
}
printf("\nSorted array -->\n");

for(i=0;i<10;i++)
printf("%d\t",arr[i]);

getch();
 }

/* WAP TO PRINT THE FOLLOWING FORMAT  :-


A B C D E F G F E D C B A
A B C D E F     F E D C B A
A B C D E            E D C B A
A B C D                   D C B A
A B C                           C B A
A B                                   B A
A                                          A  


#include<stdio.h>
#include<conio.h>
 void main()
 {
int i,j;
int k,l,m;

clrscr();

j=71;
k=j;

for(i=0;i<7;i++)
{
l=65;
while(l<=k)
{
printf(" %c",l);
l++;
}
if(i==0)
l=l-2;
else
{
for(m=1;m<(2*i-1);m++)
{
printf(" ");
}
l=l-1;
}
while(l>=65)
{
if(i==0)
printf(" %c",l);
else
printf(" %c",l);

l--;
}
printf("\n");
k--;
i++;
}
getch();
 }

FOLLOWING FORMAT

/* WAP TO PRINT THE FOLLOWING FORMAT  :-


   1
         2   3
4   5   6
     7   8   9   10  



#include<stdio.h>
#include<conio.h>
 void main()
 {
int i,j,m=1;
int space;

clrscr();

space=3;
for(i=1;i<=4;i++)
{
for(j=1;j<=space;j++)
{
printf("  ");                     // 2-SPACES.
}
for(j=1;j<=i;j++)
{
printf("%d   ",m);
m++;
}
printf("\n");
space=space-1;
}
getch();
 }
/* WAP TO PRINT THE FOLLOWING FORMAT  :-
   *
 *   *
*   *   *
     *   *   *   *
   *   *   *   *   *          


#include<stdio.h>
#include<conio.h>
 void main()
 {
int i,j;
int row,space;

clrscr();

printf("Enter the no. of rows you want= ");
scanf("%d",&row);
clrscr();
space=row-1;
for(i=1;i<=row;i++)
{
for(j=1;j<=space;j++)
{
printf("  ");                     // 2-SPACES.
}
for(j=1;j<=i;j++)
{
printf("*   ");                   // 1 * & 3-SPACES.
}
printf("\n");
space=space-1;
}
getch();
 }

USING 3rd VARIABLE

WAP TO INPUT TWO NO.S AND INTERCHANGE THEIR VALUE USING 3rd VARIABLE

#include<stdio.h>
#include<conio.h>

void main()
{
      int num1;
      int num2;
      int num3;

      clrscr();
      printf("\nEnter 1st no.=");
      scanf("%d",&num1);
      printf("Enter 2nd no.=");
      scanf("%d",&num2);
      num3=num1;
      num1=num2;
      num2=num3;
      printf("\nswapped value of num1=%d",num1);
      printf("\nswapped value of num2=%d\n",num2);
      getch();

}

Friday, December 13, 2013

 /* WAP TO PRINT THE FOLLOWING FORMAT  :-

     *
 *    *
*   *   *
     *   *   *   *
   *   *   *   *   *
      *
      *
      *
      *
      *                


#include<stdio.h>
#include<conio.h>
 void main()
 {
int i,j,k;
int row,space;

clrscr();

printf("Enter the total no. of rows you want= ");
scanf("%d",&row);
clrscr();
space=row/2-1;
for(i=0;i<row/2;i++)
{
for(j=0;j<space;j++)
printf("  ");

if(i==0 || i==row/2-1)
{
for(j=0;j<=i;j++)
printf("*   ");
}
else
{
for(j=0;j<2;j++)
{
printf("*");
for(k=0;k<4*i-1;k++)
printf(" ");
}
}
printf("\n");
space=space-1;
}
for(i=row/2;i<row;i++)
{
space=row/2-1;
for(j=0;j<space;j++)
{
printf("  ");
}
printf("*\n");
}
getch();
 }

Tuesday, November 19, 2013

STRING


Que:- WAP TO INPUT ANY STRING AND COUNT NO. OF VOWELS.

#include<stdio.h>
#include<conio.h>

 void main()
 {
char str[20];
int i;
int vc=0;

clrscr();

printf("\n Enter any string -->  ");
scanf("%s",str);

i=0;
while(str[i]!='\0')
{
if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'||str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U')
vc++;
i++;
}
printf("\n No. of vowels in %s= %d",str,vc);
getch();
 }

Wednesday, November 13, 2013

FOLLOWING FORMAT

/* WAP TO PRINT THE FOLLOWING FORMAT  :-
   *
 *   *
*   *   *
     *   *   *   *
   *   *   *   *   *           



#include<stdio.h>
#include<conio.h>
 void main()
 {
int i,j;
int row,space;

clrscr();

printf("Enter the no. of rows you want= ");
scanf("%d",&row);
clrscr();
space=row-1;
for(i=1;i<=row;i++)
{
for(j=1;j<=space;j++)
{
printf("  ");                     // 2-SPACES.
}
for(j=1;j<=i;j++)
{
printf("*   ");                   // 1 * & 3-SPACES.
}
printf("\n");
space=space-1;
}
getch();
 }

FOLLOWING FORMAT

/* WAP TO PRINT THE FOLLOWING FORMAT  :-
   *
 *   *
*   *   *
     *   *   *   *
   *   *   *   *   *           



#include<stdio.h>
#include<conio.h>
 void main()
 {
int i,j;
int row,space;

clrscr();

printf("Enter the no. of rows you want= ");
scanf("%d",&row);
clrscr();
space=row-1;
for(i=1;i<=row;i++)
{
for(j=1;j<=space;j++)
{
printf("  ");                     // 2-SPACES.
}
for(j=1;j<=i;j++)
{
printf("*   ");                   // 1 * & 3-SPACES.
}
printf("\n");
space=space-1;
}
getch();
 }

/*WAP TO PRINT THE FOLLOWING FORMAT:
      *
      # #
      * * *
      # # # #
      * * * * *      


#include<stdio.h>
#include<conio.h>
 void main()
 {
int i;
int j;

clrscr();

for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
if(i%2!=0)
printf(" *");
else
printf(" #");
}
printf("\n");
}
getch();
 }












#include<stdio.h>
#include<conio.h>
 void main()
 {
int i,j;
int row,space;

clrscr();

printf("Enter the no. of rows you want= ");
scanf("%d",&row);
clrscr();
space=row-1;
for(i=1;i<=row;i++)
{
for(j=1;j<=space;j++)
{
printf("  ");
}
for(j=1;j<=i;j++)
{
printf("* ");
}
printf("\n");
space=space-1;
}
getch();
 }

Tuesday, November 5, 2013

SUM OF THE SREIES

/*THE NATURAL LOGARITHM CAN BE APPROXIMATED BY THE FOLLOWING SERIES: (x-1/x)+[1/2(x-1/x)*(x-1/x)]+[1/2(x-1/x)*(x-1/x)*(x-1/x)].....upto 7 terms.  IF x IS INPUT THROUGH THE KEYBOARD, WAP OT CALCULATE SUM OF THE SREIES*/



#include<stdio.h>
#include<conio.h>
#include<math.h>
 void main()
 {
int x;
int i;
float sum=0;

clrscr();

printf("\nEnter the value of x= ");
scanf("%d",&x);

if(x!=0)
{
for(i=1;i<=7;i++)
{
if(i==1)
sum=sum+pow(((x-1.0)/x),i);

else
sum=sum+(1.0/2)*pow(((x-1.0)/x),i);
}
printf("\nSum of the given series= %f",sum);
}

else
printf("\n\tERROR.\n\tYou have entered a wrong input.");
getch();
 }

Thursday, October 24, 2013

FOLLOWING SERIES

/*WAP TO ADD 1st SEVEN TERMS OF THE FOLLOWING SERIES: (1/1!)+(2/2!)+.......+(7/7!) [using FOR loop]*/


#include<stdio.h>
#include<conio.h>
 void main()
 {
int i,j;
float fact;
float sum=0;

clrscr();
printf("\nGiven series -->\n\t\t");
printf("1/1! + 2/2! + 3/3! + 4/4! + 5/5 + 6/6! + 7/7!");
for(i=1;i<=7;i++)
{
fact=1;
for(j=1;j<=i;j++)
{
fact=fact*j;
}
sum=sum+i/fact;
}
printf("\n\n\nSum of the 1st seven terms of the given series= %f",sum);
getch();
 }

ARMSTRONG NO

/* WAP TO PRINT AND COUNT ARMSTRONG NO.S FROM 1 TO 1000.



#include<stdio.h>
#include<conio.h>
 void main()
 {
int num;
int n;
int d,sum;
int count=0;

clrscr();

printf("\nArmstrong no.s from 1 to 1000 -->\n\n\t\t");
num=1;
while(num<1000)
{
n=num;
sum=0;
while(n>0)
{
d=n%10;
sum+=d*d*d;
n=n/10;
}
if(num==sum)
{
printf("%d\t",num);
count++;
}
num++;
}
printf("\n\nTotal no. of Armstrong no.s from 1 to 1000 = %d",count);
getch();
 }

Wednesday, October 23, 2013

SUM OF ALL 3-DIGITS

//WAP TO INPUT A 3-DIGIT NO. AND CALCULATE SUM OF ALL DIGITS.


#include<stdio.h>
#include<conio.h>
void main()
{
      int num;
      int r,sum=0;
      clrscr();

      printf("\nEnter a 3-digit no.=");
      scanf("%d",&num);
      r=num%10;
      sum=sum+r;
      num=num/10;
      r=num%10;
      sum=sum+r;
      num=num/10;
      r=num%10;
      sum=sum+r;
      printf("\n\nThe sum of all digits of entered no.=%d",sum);
      getch();


}

Tuesday, October 22, 2013

MULTI-DIGITS NO.STRING

  /*WAP TO INPUT TWO MULTI-DIGITS NO.S AND COUNT NO. OF DIGITS IN BOTH NO.S .


#include<stdio.h>
#include<conio.h>
 void main()
 {
long int n1,n2;
int count1=0;
int count2=0;

clrscr();

printf("\nEnter 1st multi-digit no.(non-zero)= ");
scanf("%ld",&n1);
printf("\nEnter 2nd multi-digit no.(non-zero)= ");
scanf("%ld",&n2);

while(n1>0)
{
n1=n1/10;
count1+=1;
}
while(n2>0)
{
n2=n2/10;
count2+=1;
}

printf("\nNo. of digits in 1st no.= %d",count1);
printf("\nNo. of digits in 2nd no.= %d",count2);

if(count1==count2)
printf("\n\nBoth no.s have same no. of digits.");
else
printf("\n\nBoth no.s have different no. of digits.");

getch();
 }

Monday, October 21, 2013

ADDITION, SUBTARCTION,MULTIPLICATION, DIVISION OF TWO NO.

*WAP TO ENTER TWO NO.S AND PERFOERM ADDITION, SUBTARCTION,MULTIPLICATION, DIVISION.


#include<stdio.h>
#include<conio.h>

 void main()
 {
      float a;
      float b;      // donot input b=0, in the case of                                   division.
      float r;

      clrscr();
      printf("\nEnter 1st no.=");
      scanf("%f",&a);
      printf("\nEnter 2nd no.=");
      scanf("%f",&b);
      r=a+b;                // Here r stands for addition.
      printf("\nAddition of two no.s=%f",r);
      r=a-b;               // Here r stands for subtraction.
      printf("\nSubtraction of two no.s=%f",r);
      r=a*b;              // Here r stands for multiplication.
      printf("\nMultiplication of two no.s=%f",r);
      r=a/b;             // Here r stands for division.
      printf("\nDivision of two no.s=%f",r);
      getch();

 }

Sunday, October 20, 2013

PRINT ALL THE ASCII VALUES

1. WAP TO PRINT ALL THE  ASCII VALUES AND THEIR EQUIVALENT CHARACTERS.


(Due to space-problem on the screen, ASCII-value is only taken upto
 190. Otherwise, range of ASCII value is - [0 -255] )   */

#include<stdio.h>
#include<conio.h>
 void main()
 {
int i;

clrscr();

i=0;
while(i<=190)
{

if(i<=22)
{
printf("%d - %c\n",i,i);

}
else if(i<=46)
{
gotoxy(10,i-22);
printf("  %d - %c\n",i,i);
}
else if(i<=70)
{
gotoxy(20,i-46);
printf("  %d - %c\n",i,i);
}
else if(i<=94)
{
gotoxy(30,i-70);
printf("  %d - %c\n",i,i);
}
else if(i<=118)
{
gotoxy(40,i-94);
printf("  %d - %c\n",i,i);
}
else if(i<=142)
{
gotoxy(50,i-118);
printf("  %d - %c\n",i,i);
}
else if(i<=166)
{
gotoxy(60,i-142);
printf("  %d - %c\n",i,i);
}
else if(i<=190)
{
gotoxy(70,i-166);
printf("  %d - %c\n",i,i);
}
i++;
}
getch();
 }

Saturday, October 19, 2013

USING 3rd VARIABLE

  1. WAP TO INPUT TWO NO.S AND INTERCHANGE THEIR VALUE USING 3rd VARIABLE


#include<stdio.h>
#include<conio.h>

void main()
{
      int num1;
      int num2;
      int num3;

      clrscr();
      printf("\nEnter 1st no.=");
      scanf("%d",&num1);
      printf("Enter 2nd no.=");
      scanf("%d",&num2);
      num3=num1;
      num1=num2;
      num2=num3;
      printf("\nswapped value of num1=%d",num1);
      printf("\nswapped value of num2=%d\n",num2);
      getch();

}

3-D ARRAY

Que-: WRITE A PROGRAM OF MULTIPLICATION OF TWO MATRICES WITH 3-D ARRAY.



#include<stdio.h>
#include<conio.h>

 void main()
 {
int mat[3][3][3];
int k,i,j,l;

clrscr();

printf("For matrix 1 -->\n____________\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
k=0;
printf("Enter value at (%d,%d,%d)= ",k,i,j);
scanf("%d",&mat[k][i][j]);
}
}
printf("\nMatrix 1 -->\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
k=0;
printf("%d\t",mat[k][i][j]);
}
printf("\n");
}

printf("\nFor matrix 2 -->\n____________\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
k=1;
printf("Enter value at (%d,%d,%d)= ",k,i,j);
scanf("%d",&mat[k][i][j]);
}
}
printf("\nMatrix 2 -->\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
k=1;
printf("%d\t",mat[k][i][j]);
}
printf("\n");
}

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
k=2;
mat[k][i][j]=0;
for(l=0;l<3;l++)
{
mat[k][i][j]+=mat[0][i][l]*mat[1][l][j];
}
}
}
printf("\nProduct of the above two matrices -->\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
k=2;
printf("%d\t",mat[k][i][j]);
}
printf("\n");
}
getch();
 }





2:- WAP TO CREATE A 5*5 MATRIX AND INPUT '*' IN 1st ROW & ON 2nD ROW - INPUT # & SO ON.....


#include<stdio.h>
#include<conio.h>
 void main()
 {
int mat[5][5];
int i,j;

clrscr();

printf("\nRequired pattern -->\n\n");
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(i%2==0)
printf("* ");
else
printf("# ");
}
printf("\n");
}
getch();
 }

Thursday, September 19, 2013

Sequential Construction


1. Write a program to compute the simple intrest ?
#include<stdio.h>
#include<conio.h>
    
    void main()
   {
    int p,r,t,s;
    clrscr();
    printf("enter principle:\n");
    scanf("%d",&p);
    printf("enter rate:\n");
    scanf("%d",&r);
    printf("enter time:\n");
    scanf("%d",&t);
    s=(p*r*t)/100;
    printf("s.i=%d",s);
   getch();
 }





2. Write a program(WAP) to find sum of any two numbers?

#include<stdio.h>
#include<conio.h>
   void main()
 {
    int a,b,c;
    clrscr();
    printf("Enter first number:\n");
   scanf("%d",&a);
   printf("Enter second number:\n");
   scanf("%d",&b);
   c=a+b;
   printf("sum=%d",c);
   getch();
}


3.WAP to calculate area of rectangle.

#include<stdio.h>
#include<conio.h>
   void main()
  { 
    int l,b,A;
    clrscr();
    printf("Enter length:\n");
    scanf("%d",&l);
    printf("Enter bredth:\n");
    scanf("%d",&b);
    A=l*b;
    printf("Area of rectangle=%d",A);
   getch();
}
  

4.WAP to calculate Area of triangle by heros formula?

#include<math.h>
#include<conio.h>
#include<stdio.h>
   
void main()
{
 int a,b,c,s,Area;
 clrscr();
 printf("Enter sides a:\n");
 scanf("%d",&a);
 printf("Enter sides b:\n");
 scanf("%d",&b);
 printf("Enter sides c:\n");
 scanf("%d",&c);
 s=(a+b+c)/2;
 Area=sqr[s*(s-a)*(s-b)*(s-c)];
 printf("Area of triangle=%d",Area);
 getch();
}





5.WAP to enter value of two number and swap the valu.

#include<stdio.h>
#include<conio.h>
  void main()
 {
  int a,b,c;
  printf("Enter first number:\n");
  scanf("%d",&a);
  printf("Enter second number:\n");
  scanf("%d",&b);
    c=a;
    a=b;
    b=c;
  printf("Enter the value of a=%d",a);
  printf("Enter the value of b=%d",b);
 getch();
}


6.WAP a program to Enter two number and swaps the value without using third variables?


#include<stdio.h>
#include<conio.h>

  void main()
  {
  int a,b;
  printf("Enter first number:\n");
  scanf("%d",&a);
  printf("Enter second number:\n");
  scanf("%d",&b);
    a=a+b;
    b=a-b;
    a=a-b;
  printf("The value of a=%d",a);
  printf("The value of b=%d",b);
  getch();
}




Tuesday, August 13, 2013

DBMS

Que :- Discuss concepts of  RDBMS with Codde Rule ?
                                   or
                    Discuss 12th Rule of Coddes?



Any RDBMS package is bashed on  coddes rule. Dr E.F codde is a mathematician  that provide 12th rule of Relational Data Model. These are follow :-


1)  Information Rule 
2)  Granted access Rule
3) Systematic Treatment of Null value
4) Active Online Catalog Based on relational principle 
5) View  Updating Rule 
6) Integrity Independence Rule 
7) Relational Manipulation Rule
8) Physical Data In dependency  
9) Logical Data in dependency
10) High Level Insert, Delete and update
11) Non-sub version Rule
12) Distribution Independence



1)  Information Rule :-
        
 This rule is about the storing the information  Dr. E.F codde suggest that information storage in relational data model in the form of relation where relation as treated as table with in intersection of row and column where each row represent one record and where each column represent field create a record it create database.
                                                                                   If we want to store information about any course then we have to create  a relation with required number of attributes (Field) in any RDBMS package.



2) Granted access Rule:-
       
 This rule about the accessing of data in each relation Dr. E.F Codde suggest that every piece  of information in a relation is uniquely access with any ambiguity (with out any confusion) after getting this rule all RDBMS package suggest a concept of primary key it is that field in table that never be duplicate and that never be NULL.using this field we can access all other field within a relation uniquely  there is only one primary key in each relation.
              This concept is given functional dependency where another attribute of a relation is dependent on primary key of that relation.
                                                                           


3) Systematic Treatment of Null value :-
        
 During collecting information about entity many of the information is missing for ex:-if we collect information about any employee i,e newly join in an organisation  then all his information feed in employee relation but till now his department is  not decided now question is that what is the value of Department field,some people suggest about this situation that is if field type is character put space,if field type is numeric  put zero (0) but Dr. E.F codde suggest that put NULL in missing information .





4) Active Online Catalog Based on relational principle  :-

      Dr. E.F codde suggest that there must be a provision to store data about data means if we want to create any data in relation database like tupple , processor, view etc then all RDBMS package store information about this object i.e on which date is create  and time is created whose reader of that object on which time which is created. storing data about data should be in the form of relation it should be or created automatically.




5) View  Updating Rule  :-

This rule  about the user view if we create any view for any user then it should be up datable.each user required different amount of data for this purpose codde`s suggest that RDBMS package should has a provision to create a view for different user.



6) Integrity Independence Rule  :-


This rule about the integrity about of database if any integrity (rule) is impose on any attributes then the maintains of this integrity  should be independence from data.


7) Relational Manipulation Rule :-

In all RDBMS package data are store in the form of relation then DR. E.F codde  suggest there  should be a language that perform operation on relation. Relational algebra and relational calculus is prosigeral RDBMS package that has tools to perform operation on relation there are the some basic operation perform by relational algebra 
i.e as follow :-
   
select, projection, Division, Cartesian product, join, set different, union, intersection etc.



8) Physical Data Independency  :-

This rule about the data independency it suggest that physical data of a database should independence from logical data. 


9) Logical Data in dependency :-

This rule about the maintaining of logical data independence from the external data.


10) High Level Insert, Delete and update :-

This rule is about the interface  to performing operation with any RDBMS generally we perform three operations i.e insert,delete and update.this three operation can be perfome sucessfully.


11) Non-sub version Rule :-

This rule about the low level language for handing the database. if it is used then relational principle should not be violate (break down).


 12) Distribution Independence :-


This rule about the data distribution  if more than one user perform operation on  single database then they are unaware from data. 

Saturday, August 10, 2013

Stack vs Queue

Stack vs Queue 
Stack is an ordered list in which insertion and deletion of list items can be done only in one end called the top. Due to this reason, stack is considered as a Last in First out (LIFO) data structure. Queue is also an ordered list in which insertion of list items are done in one end called the rear, and the deletion of items are done in the other end called the front. This insertion and deletion mechanism makes the queue a First in First out (FIFO) data structure.
What is Stack?
As mentioned earlier, stack is a data structure in which elements are added and removed from only one end called the top. Stacks allow only two fundamental operations called push and pop. The push operation adds a new element to the top of the stack. The pop operation removes an element from the top of the stack. If the stack is already full, when a push operation is performed, it is considered as a stack overflow. If a pop operation is performed on an already empty stack, it is considered as a stack underflow. Due to the small number of operations that could be performed on a stack, it is considered as a restricted data structure. Additionally, according to the way that the push and pop operations are defined, it is clear that elements that were added last in to the stack go out of the stack first. Therefore stack is considered as a LIFO data structure.






What is Queue?
In a queue, elements are added from the rear of the queue and removed from the front of the queue. Since the elements that are added first will be removed from the queue first, it maintains the FIFO order. Due to this order of adding and removing elements, queue represents the idea of a checkout line. General operations supported by a queue are en-queue and de-queue operations. En-queue operation will add an element at the rear of the queue, while the de-queue operation removes an element from the front of the queue. In general, queues do not have a limit on the number of elements that can be added to the queue besides the memory constraints.



What is the difference between Stack and Queue?
Even though both the stacks and queues are kinds of ordered lists, they have some important differences. In stacks, adding or deleting items can be done only from one end called the top, while in queues adding items is done from one end called the rear and deleting items is done from the other end called the front. In a stack, items that are added last to the stack will be removed first from the stack. Therefore stack is considered as a LIFO data structure. In queues, items that are added first will be removed from the queue first. Therefore queue is considered as a FIFO data structure.







What are the Differences between stack and queue?






  • A stack is generally First In, Last Out,  and a queue is First In First Out.
  • Data or elements can be added or removed only at one end in stack and in a queue insertion at the rear and deletion from the front.
  • The basic operation of stack are 'push' and 'pop', on other hand of queue are 'enque' and 'dequeue'.
  •  STACK = LIFO Last In First Out .  
  •  Stack is a data dtructure in which addition of new element or deletion of an existing element pop.
  •  Stack is also called last-in-first-out list.  
                                  
  •  QUEUES = FIFO First In First Out .
  • Queues is a linear data structure that permits insertion of new element at one end and deletion of element at the other end.