Wednesday 11 June 2014

stack implementation using Linked List In C Programing

#include<stdio.h>
#include<conio.h>
void push_stack ();
void pop_stack ();
void display_stack ();

typedef struct node
{
int data_stack ;
struct node *link;
}d;
d*top=NULL;


main()
{
int d;
printf("\tMENU\n1.PUSH_STACK \n2.POP_STACK \n3.DISPLAY_STACK \n4.EXIT\n");
do
{
printf("\nEnter your choice\n");
scanf("%d",&d);
switch(d)
{
case 1:
push_stack ();
break;
case 2:
pop_stack ();
break;
case 3:
display_stack ();
break;
case 4:
break;
default:
printf("Invalid choice\n");
break;
}
}
while(d!=4);
}


void push_stack ()
{
int item;
d *temp;
printf("Enter the item\n");
scanf("%d",&item);
temp=(d*)malloc(sizeof(d));
temp->data_stack =item;
temp->link=top;
top=temp;
}

void pop_stack ()
{
d *temp;
if(top==NULL)
printf("Stack is empty\n");
else
{
temp=top;
printf("The element deleted = %d\n",temp->data_stack );
top=top->link;

free(temp);
}
}

void display_stack ()
{
d *save;
if(top==NULL)
printf("Stack is empty\n");
else
{
save=top;
printf("The elements of the stack are :");
while(save!=NULL)
{
printf("%d\t",save->data_stack );
save=save->link;
}
printf("\nTopmost element = %d\n",top->data_stack );
}
}

Create Stack And Insert Data Using C Programming

#include<stdio.h>
#include<conio.h>
#define col 4
#define row 4

void main()
{
            int i,n,j;
            float ax[row+1], ay[col+1],diff[row+1][col+1],x,p,ya1,ya2,ya3,ya4,ya,ha;

            clrscr();

            printf("Enter thae value of n:");
            scanf("%d",&n);

            printf("\n Enter thae values of X and Y:\n");
            for(i=0; i<=n; i++)
            {
                        scanf("%f %f",&ax[i],&ay[i]);
            }

            printf("Value of X:");
            scanf("%f",&x);

            ha=ax[1]-ax[0];

            for(i=0; i<=n-1; i++)
                        diff[i][1]=ay[i+1]-ay[i];
            for(j=2; j<=row; j++)
                        for(i=0; i<=n-j; i++)
                                    diff[i][j]=diff[i+1][j-1]-diff[i][j-1];

            p=(x-ax[0])/ha;
            ya1=p*diff[0][1];
            ya2=p*(p-1)*diff[0][2]/2;
            ya3=p*(p-1)*(p-2)*diff[0][3]/6;
            ya4=p*(p-1)*(p-2)*(p-3)*diff[0][4]/24;
            ya=ay[0]+ya1+ya2+ya3+ya4;
            printf("%f",ya);
            getcha();



}

Create Stack Using C Programming

#include<stdio.h>
#include<conio.h>
#define col 4
#define row 4

void main()
{
            int i,n,j;
            float ax[row+1], ay[col+1],diff[row+1][col+1],x,p,ya1,ya2,ya3,ya4,ya,ha;

            clrscr();

            printf("Enter thae value of n:");
            scanf("%d",&n);

            printf("\n Enter thae values of X and Y:\n");
            for(i=0; i<=n; i++)
            {
                        scanf("%f %f",&ax[i],&ay[i]);
            }

            printf("Value of X:");
            scanf("%f",&x);

            ha=ax[1]-ax[0];

            for(i=0; i<=n-1; i++)
                        diff[i][1]=ay[i+1]-ay[i];
            for(j=2; j<=row; j++)
                        for(i=0; i<=n-j; i++)
                                    diff[i][j]=diff[i+1][j-1]-diff[i][j-1];

            p=(x-ax[0])/ha;
            ya1=p*diff[0][1];
            ya2=p*(p-1)*diff[0][2]/2;
            ya3=p*(p-1)*(p-2)*diff[0][3]/6;
            ya4=p*(p-1)*(p-2)*(p-3)*diff[0][4]/24;
            ya=ay[0]+ya1+ya2+ya3+ya4;
            printf("%f",ya);
            getcha();



}