To implement queue using array

#include<stdio.h>
#include<conio.h>
#define MAX 10
void insert(int);
int del();
int queue[MAX], rear=0, front=0;
void display();
int main()
{
     char ch , a='y';
     int choice, token;
     printf("1.Insert");
     printf("\n2.Delete");
     printf("\n3.show or display");
     do
     {
           printf("\nEnter your choice for the operation: ");
           scanf("%d",&choice);
          switch(choice)
          {
                case 1: insert(token);
                display();
                break;

                case 2:
                token=del();
                printf("\nThe token deleted is %d",token);
                display();
                break;

                case 3:
                display();
                break;

                default:
                printf("Wrong choice");
                break;
          }
          printf("\nDo you want to continue(y/n):");
          ch=getch();
    }
    while(ch=='y'||ch=='Y');
    getch();
}
void display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=rear;i<front;i++)
    {
        printf("%d ",queue[i]);
    }
}
void insert(int token)
{
    char a;
    if(rear==MAX)
    {
        printf("\nQueue full");
        return;
    }
    do
    {
        printf("\nEnter the token to be inserted:");
        scanf("%d",&token);
        queue[front]=token;
        front=front+1;
        printf("do you want to continue insertion Y/N");
        a=getch();
    }
    while(a=='y');
}
int del()
{
    int t;
    if(front==rear)
    {
        printf("\nQueue empty");
        return 0;
    }
    rear=rear+1;
    t=queue[rear-1];
    return t;
}
--------------------------------------------------------------------------------------------------------------------------------------------------
OUTPUT : -


To implement stack using linked list

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct stack {
   int data;
   struct stack *next;
} node;
void main() {
   node *top;
   int data, item, choice;
   char ans, ch;
   top = NULL;
   printf("\nStack Using Linked List : \n\n");
   do {
      printf("\n\n The main menu : ");
      printf("\n1.Push \n2.Pop \n3.Display \n4.Exit");
      printf("\n Enter Your Choice : ");
      scanf("%d", &choice);
      switch (choice) {
      case 1:
         printf("\nEnter the data : ");
         scanf("%d", &data);
         Push(data, &top);
         break;
      case 2:
         if (Sempty(top))
            printf("\nStack underflow!");
         else {
            item = Pop(&top);
            printf("\nThe popped node is%d", item);
         }
         break;
      case 3:
         Display(&top);
         break;
      case 4:
         printf("\nDo You want To Quit?(y/n)");
         ch = getche();
         if (ch == 'y')
            exit(0);
         else
            break;
      }
      printf("\nDo you want to continue? ");
      ans = getche();
      getch();
   } while (ans == 'Y' || ans == 'y');
   getch();
}
void Push(int Item, node **top) {
   node *New;
   node * get_node(int);
   New = get_node(Item);
   New->next = *top;
   *top = New;
}
node * get_node(int item) {
   node * temp;
   temp = (node *) malloc(sizeof(node));
   if (temp == NULL)
      printf("\nMemory Cannot be allocated");
   temp->data = item;
   temp->next = NULL;
   return (temp);
}
int Sempty(node *temp) {
   if (temp == NULL)
      return 1;
   else
      return 0;
}
int Pop(node **top) {
   int item;
   node *temp;
   item = (*top)->data;
   temp = *top;
   *top = (*top)->next;
   free(temp);
   return (item);
}
void Display(node **head) {
   node *temp;
   temp = *head;
   if (Sempty(temp))
      printf("\nThe stack is empty!");
   else {
      while (temp != NULL) {
         printf("%d\n", temp->data);
         temp = temp->next;
      }
   }
   getch();
}

------------------------------------------------------------------------------------------------------------------------------------------------
OUTPUT : -


To implement stack using array

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define size 5
struct stack {
   int s[size];
   int top;
} st;
int stfull() {
   if (st.top >= size - 1)
      return 1;
   else
      return 0;
}
void push(int item) {
   st.top++;
   st.s[st.top] = item;
}
int stempty() {
   if (st.top == -1)
      return 1;
   else
      return 0;
}
int pop() {
   int item;
   item = st.s[st.top];
   st.top--;
   return (item);
}
void display() {
   int i;
   if (stempty())
      printf("\nStack Is Empty!");
   else {
      for (i = st.top; i >= 0; i--)
         printf("\n%d", st.s[i]);
   }
}
int main() {
   int item, choice;
   char ans;
   st.top = -1;
   printf("\n\tImplementation Of Stack");
   do {
      printf("\nMain Menu");
      printf("\n1.Push \n2.Pop \n3.Display \n4.exit");
      printf("\nEnter Your Choice");
      scanf("%d", &choice);
      switch (choice) {
      case 1:
         printf("\nEnter The item to be pushed");
         scanf("%d", &item);
         if (stfull())
            printf("\nStack is Full!");
         else
            push(item);
         break;
      case 2:
         if (stempty())
            printf("\nEmpty stack!Underflow !!");
         else {
            item = pop();
            printf("\nThe popped element is %d", item);
         }
         break;
      case 3:
         display();
         break;
      case 4:
         exit(0);
      }
      printf("\nDo You want To Continue?");
      ans = getche();
   } while (ans == 'Y' || ans == 'y');
return 0;
}


OUTPUT : -----------------------------------------------------------------------------------------------------------

To transpose a 2D array

#include<stdio.h>
#include<conio.h>
int main()
{
    int a[10][10], trans[10][10],r,c,i,j;
    printf("Enter the row and column of matrix :\n");
    scanf("%d%d",&r,&c);
    printf("\nEnter the element of 1st matrix : \n");
    for(i=0;i<r;i++)
        {
            for(j=0;j<c;j++)
            {
                printf("Enter element of 1st matrix %d%d: ",i,j);
                scanf("%d",&a[i][j]);
            }
        }
    printf("\nEnter matrix : \n");
    for(i=0;i<r;i++)
        {
            for(j=0;j<c;j++)
            {
                printf("%d",a[i][j]);
                if(j==c-1)
                {
                    printf("\n\n");
                }
            }
        }
   for(i=0;i<r;i++)
        {
            for(j=0;j<c;j++)
            {
              trans[j][i]=a[i][j];
            }
        }
    printf("\n Transpose of matrix : \n");
     for(i=0;i<r;i++)
        {
            for(j=0;j<c;j++)
            {
                printf("%d",trans[i][j]);
                if(j==r-1)
                {
                    printf("\n\n");
                }
            }
        }
    return 0;
}


OUTPUT : - 

To implement addition and multiplication of two 2D arrays.

#include<stdio.h>
#include<conio.h>
typedef struct complex
 {
    float real;
    float imag;
}complex;
    complex add(complex, complex);
    complex multiply(complex, complex);
    int main()
    {
        complex n1,n2,sum,mul;
        printf("\t For first complex number : \n");
        printf("Enter real and imaginary respectively :\n");
        scanf("%f%f",&n1.real,&n1.imag);
        printf("\n\t For second complex number : \n");
        printf("Enter real and imaginary respectively :\n");
        scanf("%f%f",&n2.real,&n2.imag);
        sum=add(n1,n2);
        mul=multiply(n1,n2);
        printf("\t Sum = %.1f+%.1f1",sum.real,sum.imag);
        printf("\t Multiply = %.1f+%.1f1",mul.real,mul.imag);
    }
    complex add(complex n1, complex n2)
        {
            complex temp;
            temp.real=n1.real+n2.real;
            temp.imag=n1.imag+n2.imag;
            return temp;
        }
    complex multiply(complex n1, complex n2)
        {
            complex temp;
            temp.real=n1.real*n2.real-n1.imag*n2.imag;
            temp.imag=n1.real*n2.real+n1.real*n2.real;
            return temp;
}


OUTPUT :-

Data Structure Practical File