Posts

Showing posts from August, 2017

Different functions of Linked List using menu driven approach

/*insertend(),inserbef(),insertatpos() functions are used to create a linked using its position value,del() function will delete the element you have specified,disp() function is used to display the elements in the linked list*/ #include<stdio.h> #include<stdlib.h> typedef struct Linked { int val; struct Linked *next; }lnk; lnk* insertbeg(lnk *,int); lnk* insertend(lnk *,int); lnk *insertatpos(lnk *,int,int); lnk *del(lnk *,int); void disp(lnk *); int main() { lnk *head=NULL; int ch,v,p; while(1) { printf("\n1)Insert End\n2) Insert begining\n3)Insert at Position\n4)Delete\n5)Display\n6)Exit"); printf("\n Enter your choice : "); scanf("%d",&ch); switch(ch) { case 1: printf("\nEnter the value to be inserted : ");  scanf("%d",&v);  head=insertend(head,v);  break; case 2: printf("\nEnter the value to be inserted : ");  scanf("%d",&v);  head=insertbeg(head,v);  b

Linked list created and there after elements are displayed

Image
#include<stdio.h> #include<stdlib.h> typedef struct Linked { int val; struct Linked *next; }lnk; lnk* createlink(); void disp(); int main() { lnk *head; head=createlink(); printf("Values in the linked list :: "); disp(head); } lnk *createlink() { lnk *h=NULL,*tmp,*ptr; char ch; int v; while(1) { printf("\nEnter the value for the node (enter -99 to exit) : "); scanf("%d",&v); if(v==-99) return h; tmp=(lnk *)malloc(sizeof(lnk)); tmp->val=v; tmp->next=NULL; if(h==NULL) h=tmp; else ptr->next=tmp; ptr=tmp; } } void disp(lnk *h) { while(h!=NULL) { printf("%d,",h->val); h=h->next; } printf("\b"); }

Circular Queue using Structure

Image
#include<stdio.h> #include<stdlib.h> #define max 5 typedef struct Queue { int val[max]; int rear,front; }qu; void enque(qu *,int); int deque(qu*); int peek(qu); int isempty(qu); int isfull(qu); void disp(qu); void main() { qu q; int g,v; q.rear=q.front=-1; while(1) { printf("\n1) Insert\n2) Delete\n3) Peek\n4) Display\n5) Exit"); printf("\n Enter your choice :"); scanf("%d",&g); switch(g) { case 1: printf("\n Enter the value"); scanf("%d",&v); if(!isfull(q)) enque(&q,v); else printf("\nNo more space"); break; case 2: if(!isempty(q)) printf("\nDeleted element is %d",deque(&q)); else printf("\nNothing to delete"); break; case 3: if(!isempty(q)) printf("\n value at front %d",peek(q)); else printf("\n Nothing in the front"); break; case 4: if(!isempty(q)) { printf("\nValues int queue

Linear Queue using Structure

Image
#include<stdio.h> #include<stdlib.h> #define max 50 typedef struct Queue { int val[max]; int front,rear; }qu; void enqueu(qu *,int); int dequeu(qu *); int peek(qu); int isempty(qu); int isfull(qu); void disp(qu); int main() { int ch,v; qu q; q.front=q.rear=-1; while(1) { printf("\n1) Insert \n2) Delete \n3)Front value\n4)Display\n5) Exit"); printf("\n Enter the choice : "); scanf("%d",&ch); switch(ch) { case 1: if(!isfull(q)) { printf("\n Enter the value : "); scanf("%d",&v); enqueu(&q,v); } else printf("\nNo more space"); break; case 2: if(!isempty(q)) { v=dequeu(&q); printf("\nThe deleted value from the front is %d",v); } else printf("\nNothing to delete"); break; case 3: if(!isempty(q)) { printf("\nThe Value at the front is %d",peek(q)); } else printf("\nNothing in the queue"); br

Infix to Postfix conversion along with Postfix evaluation

#include<stdio.h> #include<conio.h> #define max 50 typedef struct stack { char ar[max]; int top; }st; typedef struct stack1 { float res[max]; int top; }st1; void push(st *,char); void push1(st1 *,float); char pop(st *); float pop1(st1 *); char peek(st); int isfull(st); int isempty(st); float pfixeval(char []); void intopost(char [],char []); int getpriority(char); int main() { char expr[max],res[max]; float p; printf("\nEnter the expression (in digits only) to be evaluated in Infix form and rest is our responsibility : "); gets(expr); intopost(expr,res); printf("\nThe postfix expression is : "); puts(res); p=pfixeval(res); printf("\nEvaluated result is : %f",p); getch(); } void intopost(char expr[],char res[]) { st s; char ch; int i,j; s.top=-1; for(i=0,j=0;expr[i]!='\0';i++) { if(expr[i]==' ') continue; else if(expr[i]=='(' || expr[i]=='{' || expr[i]=='[&#

Infix to Postfix conversion using stack

#include<stdio.h> #include<conio.h> #define max 50 typedef struct stack { char ar[max]; int top; }st; void push(st *,char); char pop(st *); char peek(st); int isfull(st); int isempty(st); void intopost(char [],char []); int getpriority(char); int main() { char expr[max],res[max]; printf("enter the expression : "); gets(expr); intopost(expr,res); printf("The postfix expression is : "); puts(res); getch(); } void intopost(char expr[],char res[]) { st s; char ch; int i,j; s.top=-1; for(i=0,j=0;expr[i]!='\0';i++) { if(expr[i]==' ') continue; else if(expr[i]=='(' || expr[i]=='{' || expr[i]=='[') push(&s,expr[i]); else if((expr[i]>=48 && expr[i]<=57) || (expr[i]>=65 && expr[i]<=90) || (expr[i]>=97 && expr[i]<=122)) res[j++]=expr[i]; else if(expr[i]=='+' || expr[i]=='-' || expr[i]=='*' || expr[i]=='/'