Posts

Showing posts from January, 2018

Stack operation

#include<stdio.h> #include<process.h> #include<stdlib.h> #define MAX 5    //Maximum number of elements that can be stored int top=-1,stack[MAX]; void push(); void pop(); void display(); void main() {     int ch;         while(1)    //infinite loop, will end when choice will be 4     {         printf("\n*** Stack Menu ***");         printf("\n\n1.Push\n2.Pop\n3.Display\n4.Exit");         printf("\n\nEnter your choice(1-4):");         scanf("%d",&ch);                 switch(ch)         {             case 1: push();        ...

Merge sort

#include<stdio.h> void mergesort(int a[],int i,int j); void merge(int a[],int i1,int j1,int i2,int j2); int main() {     int a[30],n,i;     printf("Enter no of elements:");     scanf("%d",&n);     printf("Enter array elements:");         for(i=0;i<n;i++)         scanf("%d",&a[i]);             mergesort(a,0,n-1);         printf("\nSorted array is :");     for(i=0;i<n;i++)         printf("%d ",a[i]);             return 0; } void mergesort(int a[],int i,int j) {     int mid;             if(i<j)     {         mid=(i+j)/2; ...

Program for Different operations on C

#include<stdio.h> #include<conio.h> #include<stdlib.h> #define MAX 10 struct stack {     int items[MAX];     int top; }; typedef struct stack st; void createEmptyStack(st *s) {     s->top=-1; } int isfull(st *s) {     if (s->top==MAX-1)         return 1;     else         return 0; } int isempty(st *s) {     if (s->top==-1)         return 1;     else         return 0; } void push(st *s) {     int newitem;     printf("Enter item to be inserted: ");     scanf("%d",&newitem);     if (isfull(s))     {         printf("STACK FULL");     }     else ...