diff --git a/DS Programs/BT.C b/DS Programs/BT.C new file mode 100644 index 0000000..0346c87 --- /dev/null +++ b/DS Programs/BT.C @@ -0,0 +1,115 @@ +#include +#include +struct tree +{ + int data; + struct tree *l,*r; +}*root,*q,*t,*p; +void insert() +{ + int e; + struct tree *n=(struct tree*)malloc(sizeof(struct tree*)); + printf("Enter data element:"); + scanf("%d",&e); + n->data=e; + n->l=NULL; + n->r=NULL; + if(root==NULL) + root=n; + else + { + p=root; + q=root; + while(p!=NULL) + { + q=p; + if(p->data>e) + p=p->l; + else + p=p->r; + } + if(q->data>e) + q->l=n; + else + q->r=n; + } +} +void ino(struct tree *p) +{ + while(p!=NULL) + { + ino(p->l); + printf("%5d",p->data); + ino(p->r); + } +} +void preo() +{ + p=root; + while(p!=NULL) + { + printf("%5d",p->data); + preo(p->l); + preo(p->r); + } +} +void posto(struct tree *p) +{ + while(p!=NULL) + { + posto(p->l); + posto(p->r); + printf("%5d",p->data); + } +} +void search() +{ + int ele; + printf("Enter element to be searched:"); + scanf("%d",&ele); + p=root; + while(p!=NULL) + { + if(p->data==ele) + { + printf("Element found!"); + break; + } + else + { + if(ele>p->data) + p=p->r; + else + p=p->l; + } + } + if(p==NULL) + printf("Element not foumd!"); +} +void main() +{ + int o,ch; + do + { + printf("\nMENU\n1.Insert\n2.Inorder\n3.Preorder\n4.Postorder\n5.Search"); + printf("\nEnter your choice:"); + scanf("%d",&o); + switch(o) + { + case 1:insert(); + break; + case 2:ino(root); + break; + case 3:preo(); + break; + case 4:posto(root); + break; + case 5:search(); + break; + } + printf("\n Enter 1 to continue:"); + scanf("%d",&ch); + }while(ch==1); + getch(); +} + diff --git a/DS Programs/CQ.C b/DS Programs/CQ.C new file mode 100644 index 0000000..f31e994 --- /dev/null +++ b/DS Programs/CQ.C @@ -0,0 +1,96 @@ +#include +#include +#define M 5 +int cq[M],f=-1,r=-1; +void ins(int val) +{ + if((f==0&&r==M-1)||(r==f-1)) + printf("\n Overflow!!"); + else + { + if(f==-1&&r==-1) + { + f=0; + r=0; + } + else if(r==M-1&&f!=0) + r=0; + else + r++; + cq[r]=val; + } +} +int del() +{ + if(f==-1&&r==-1) + { + printf("Underflow!"); + return -1; + } + else + { + int v; + if(f==r) + { v=cq[f]; + f=-1; + r=-1; + } + else + { + v=cq[f]; + f++; + } + return v; + } +} +void disp() +{ int d=f; + if(f==-1) + printf("No elements in queue!"); + else + { + printf("Queue:\n"); + while(1) + { + printf("%d\t",cq[d]); + if(d==M-1&&d!=r) + d=0; + else if(d==r) + break; + else + d++; + }} +} + +void main() +{ + int i,opt,ch,in,de; + do + { clrscr(); + printf("MENU\n1.Insert \n2.Delete \n3.Display"); + printf("\nEnter your choice:"); + scanf("%d",&ch); + switch(ch) + { + case 1: printf("Enter element to be inserted:"); + scanf("%d",&in); + ins(in); + disp(); + break; + case 2: de=del(); + if(de==-1) + break; + else + printf("\nDeleted element is:%d",de); + disp(); + break; + case 3: disp(); + break; + } + printf("\nDo you want to continue?1/0"); + scanf("%d",&opt); + }while(opt==1); + getch(); +} + + diff --git a/DS Programs/P10_118A1079.docx b/DS Programs/P10_118A1079.docx new file mode 100644 index 0000000..c9985bc Binary files /dev/null and b/DS Programs/P10_118A1079.docx differ diff --git a/DS Programs/P5_118A1079.docx b/DS Programs/P5_118A1079.docx new file mode 100644 index 0000000..b715607 Binary files /dev/null and b/DS Programs/P5_118A1079.docx differ diff --git a/DS Programs/P6_118A1079.docx b/DS Programs/P6_118A1079.docx new file mode 100644 index 0000000..f53beb9 Binary files /dev/null and b/DS Programs/P6_118A1079.docx differ diff --git a/DS Programs/P7_118A1079.docx b/DS Programs/P7_118A1079.docx new file mode 100644 index 0000000..6bf5495 Binary files /dev/null and b/DS Programs/P7_118A1079.docx differ diff --git a/DS Programs/P8_118A1079.docx b/DS Programs/P8_118A1079.docx new file mode 100644 index 0000000..6315252 Binary files /dev/null and b/DS Programs/P8_118A1079.docx differ diff --git a/DS Programs/P9_118A1079.docx b/DS Programs/P9_118A1079.docx new file mode 100644 index 0000000..2c50387 Binary files /dev/null and b/DS Programs/P9_118A1079.docx differ diff --git a/DS Programs/PE.C b/DS Programs/PE.C new file mode 100644 index 0000000..d2976de --- /dev/null +++ b/DS Programs/PE.C @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#define m 10 +char stack[m]; +int top=-1; +void push(char ch) +{ + if(top==m-1) + { + printf("Overflow!!"); + } + else + { + top++; + stack[top]=ch; + } +} +char pop() +{ + if(top==-1) + { + printf("Underflow!!"); + return -1; + } + else + { + char c=stack[top]; + top--; + return c; + } +} +int dop(int op1,int op2,char o) +{ int e; + if(o=='+') + e=op1+op2; + else if(o=='-') + e=op1-op2; + else if(o=='*') + e=op1*op2; + else if(o=='/') + e=op1/op2; + return e; +} + +void main() +{ + char s[10],o; + int a,b,i,l,r,ans; + clrscr(); + printf("Enter postfix expression:"); + scanf("%s",s); + l=strlen(s); + for(i=0;i +void main() +{ + int a[10],e,p=0,n,i,j,l,h,m; + printf("Enter the number of elements in the array:"); + scanf("%d",&n); + printf("Enter elements in array:"); + for(i=0;ie) + h=m; + else + l=m; + } + if(l>h) + printf("Element not found!"); +} + +OUTPUT: +Enter the number of elements in the array:6 +Enter elements in array:1 +3 +5 +7 +9 +11 + +Enter element to be searched:5 +Element found at position:3 diff --git a/DS Programs/dsproject.cpp b/DS Programs/dsproject.cpp new file mode 100644 index 0000000..639d048 --- /dev/null +++ b/DS Programs/dsproject.cpp @@ -0,0 +1,216 @@ +#include +#include +#include +struct event +{ + int sold,people; + char eventName[20]; + int dd,mm,yy; + int rows,col; +}; +typedef struct event e; +e EVENT={0,0}; +struct node +{ + char name[20]; + char password[20]; + int seats[20],numseats,seatsbooked; + struct node *next; +}; +typedef struct node *NODE; +NODE first=NULL; +int a[100]={0}; +int count=1; +NODE getnode() +{ + NODE x; + x=(NODE)malloc(sizeof(struct node)); + if(x==NULL) + { + printf("\nout of memory\n"); + exit(0); + } + return x; +} +void manager() +{ + char managerPassword[20]; + int choice; + printf("\nWELCOME EVENT MANAGER\nPlease enter your password:"); + scanf("%s",&managerPassword); + if(strcmpi(managerPassword,"AAKRITI")!=0) + { + printf("\nSORRY!!!!!\nwrong password\n"); + return; + } + while(1) + { + printf("\n1.Add an event\n2.Seats status\n3.Exit\n"); + scanf("%d",&choice); + + switch(choice) + { + case 1 : printf("\nName:"); + scanf("%s",EVENT.eventName); + printf("\nDate:"); + scanf("%d/%d/%d",&EVENT.dd,&EVENT.mm,&EVENT.yy); + printf("\nSeat pattern(rows and columns):"); + scanf("%d%d",&EVENT.rows,&EVENT.col); + printf("\nYOUR EVENT IS SUCCESSFULLY UPLOADED\n"); + break; + case 2 : printf("\nSEATS STATISTICS\n"); + printf("\nNumber of people registered:%d",EVENT.people); + printf("\nSeats sold=%d\n",EVENT.sold); + printf("Seats left=%d",EVENT.rows*EVENT.col-EVENT.sold); + break; + case 3 : return; + } + } +} +void existing() +{ + NODE cur; + int id,i,j,choice,num,s; + char userPassword[20]; + cur=first; + printf("\nWELCOME USER\n"); + printf("\nPlease enter your ID:"); + scanf("%d",&id); + for(i=1;inext; + printf("\nPlease enter your password:"); + scanf("%s",userPassword); + if(strcmp(userPassword,cur->password)!=0) + { + printf("\nSORRY!!!! Wrong password\n"); + return; + } + printf("\nHELLO %s",cur->name); + printf("\nWELCOME TO THE EVENT %s",EVENT.eventName); + while(1) + { + printf("\n1.Book seats\n2.See my seats\n3.Withdraw My seats\n4.Exit\nenter your choice:"); + scanf("%d",&choice); + switch(choice) + { + case 1 : if(EVENT.sold==EVENT.rows*EVENT.col) + { + printf("\nSORRY!!!!Seats are sold out\n"); + break; + } + printf("\nAVAILABLE SEATS ARE\n"); + for(i=0;iseats[i]=s; + } + (cur->numseats)+=num; + (cur->seatsbooked)+=num; + (EVENT.sold)+=num; + printf("\nYour seats are successfully booked\n"); + break; + case 2 : if(cur->seatsbooked==0) + { + printf("\nNO SEATS BOOKED YET\n"); + break; + } + printf("\nYOUR SEATS\n"); + printf("\nNumber of seats booked=%d",cur->seatsbooked); + printf("\nSeat numbers are\n"); + for(i=0;inumseats;i++) + if(cur->seats[i]!=-999) + printf("%d ",cur->seats[i]); + break; + case 3 : if(cur->seatsbooked==0) + { + printf("\nNO SEATS BOOKED YET\n"); + break; + } + printf("\nSEATS WITHDRAWAL\n"); + printf("\nEnter the number of seats you want to withdraw:"); + scanf("%d",&num); + printf("\nEnter the seat numbers:"); + for(i=0;inumseats;j++) + { + if(s==cur->seats[j]) + cur->seats[j]=-999; + } + (cur->seatsbooked)-=num; + (EVENT.sold)-=num; + } + printf("\nSeats are withdrawn successfully\n"); + break; + case 4 : return; + } + } + +} +void regester() +{ + NODE temp,cur; + printf("\nWELCOME TO THE EVENT %s",EVENT.eventName); + temp=getnode(); + temp->next=NULL; + printf("\nEnter your name:"); + scanf("%s",temp->name); + printf("\nSelect your password:"); + scanf("%s",temp->password); + temp->numseats=0; + temp->seatsbooked=0; + if(first==NULL) + { + printf("\nNOTE!!! your ID is %d",count); + first=temp; + EVENT.people++; + return; + } + cur=first; + while(cur->next!=NULL) + { + cur=cur->next; + count++; + } + cur->next=temp; + printf("\nNOTE!!! your ID is %d",count+1); + EVENT.people++; +} +int main() +{ + int choice; + printf("\nWELCOME"); + printf("\nEVENT MANAGEMENT SYSTEM\n"); + while(1) + { + printf("\n\n\n1.Event manager Login\n2.Existing User Login\n3.Regester Now\n4.Exit\nenter your choice:"); + scanf("%d",&choice); + switch(choice) + { + case 1 : manager();break; + case 2 : existing();break; + case 3 : regester();break; + default : exit(0); + } + } + return 0; +} + + diff --git a/DS Programs/ms.c b/DS Programs/ms.c new file mode 100644 index 0000000..0ed0246 --- /dev/null +++ b/DS Programs/ms.c @@ -0,0 +1,57 @@ +#include +void main() +{ + int a[10],b[10],n,m,c[20],i=0,j=0,k=0; + printf("Enter number of elements in array 1 & 2:"); + scanf("%d%d",&n,&m); + printf("Enter array 1:"); + for(i=0;i