diff --git a/11.C b/11.C new file mode 100644 index 0000000..bfafac1 --- /dev/null +++ b/11.C @@ -0,0 +1,86 @@ +#include +#include +#include + +#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 roll no 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; +} \ No newline at end of file diff --git a/13.c b/13.c new file mode 100644 index 0000000..0de2a60 --- /dev/null +++ b/13.c @@ -0,0 +1,85 @@ +//q 13 +#include + + + +void insert(); +void delete(); +void display(); +int queue_array[50]; +int rear = - 1; +int front = - 1; +main() +{ + int choice; + while (1) + { + printf("1.Insert employee numbers to queue \n"); + printf("2.Delete employee numbers from queue \n"); + printf("3.Display all employee numbers in queue \n"); + printf("4.Quit \n"); + printf("Enter your choice : "); + scanf("%d", &choice); + switch (choice) + { + case 1: + insert(); + break; + case 2: + delete(); + break; + case 3: + display(); + break; + case 4: + exit(1); + default: + printf("Wrong choice \n"); + } /* End of switch */ + } /* End of while */ +} /* End of main() */ + +void insert() +{ + int add_item; + if (rear == 50 - 1) + printf("Queue Overflow \n"); + else + { + if (front == - 1) + /*If queue is initially empty */ + front = 0; + printf("Insert the employee number in queue : "); + scanf("%d", &add_item); + rear = rear + 1; + queue_array[rear] = add_item; + } +} /* End of insert() */ + +void delete() +{ + if (front == - 1 || front > rear) + { + printf("Queue Underflow \n"); + return ; + } + else + { + printf("Employee number deleted from queue is : %d\n", queue_array[front]); + front = front + 1; + } +} /* End of delete() */ + +void display() +{ + int i; + if (front == - 1) + printf("Queue is empty \n"); + else + { + printf("Queue is : \n"); + for (i = front; i <= rear; i++) + printf("%d ", queue_array[i]); + printf("\n"); + } +} /* End of display() */ \ No newline at end of file diff --git a/Q15.C b/Q15.C new file mode 100644 index 0000000..9668689 --- /dev/null +++ b/Q15.C @@ -0,0 +1,138 @@ +/* C Program to implement queue using circular linked list*/ + +#include +#include + +struct node +{ + int info; + struct node *link; +}*rear=NULL; + +void insert(int item); +int del(); +void display(); +int isEmpty(); +int peek(); + +int main() +{ + int choice,item; + while(1) + { + printf("\n1.Insert\n"); + printf("2.Delete\n"); + printf("3.Peek\n"); + printf("4.Display\n"); + printf("5.Quit\n"); + printf("\nEnter your choice : "); + scanf("%d",&choice); + + switch(choice) + { + case 1: + printf("\nEnter the element for insertion : "); + scanf("%d",&item); + insert(item); + break; + case 2: + printf("\nDeleted element is %d\n",del()); + break; + case 3: + printf("\nItem at the front of queue is %d\n",peek()); + break; + case 4: + display(); + break; + case 5: + exit(1); + default: + printf("\nWrong choice\n"); + }/*End of switch*/ + }/*End of while*/ +}/*End of main()*/ + +void insert(int item) +{ + struct node *tmp; + tmp=(struct node *)malloc(sizeof(struct node)); + tmp->info=item; + if(tmp==NULL) + { + printf("\nMemory not available\n"); + return; + } + + if( isEmpty() ) /*If queue is empty */ + { + rear=tmp; + tmp->link=rear; + } + else + { + tmp->link=rear->link; + rear->link=tmp; + rear=tmp; + } +}/*End of insert()*/ + +del() +{ + int item; + struct node *tmp; + if( isEmpty() ) + { + printf("\nQueue underflow\n"); + exit(1); + } + if(rear->link==rear) /*If only one element*/ + { + tmp=rear; + rear=NULL; + } + else + { + tmp=rear->link; + rear->link=rear->link->link; + } + item=tmp->info; + free(tmp); + return item; +}/*End of del()*/ + +int peek() +{ + if( isEmpty() ) + { + printf("\nQueue underflow\n"); + exit(1); + } + return rear->link->info; +}/* End of peek() */ + +int isEmpty() +{ + if( rear == NULL ) + return 1; + else + return 0; +}/*End of isEmpty()*/ + + +void display() +{ + struct node *p; + if(isEmpty()) + { + printf("\nQueue is empty\n"); + return; + } + printf("\nQueue is :\n"); + p=rear->link; + do + { + printf("%d ",p->info); + p=p->link; + }while(p!=rear->link); + printf("\n"); +}/*End of display()*/ \ No newline at end of file diff --git a/RUBLIST.C b/RUBLIST.C new file mode 100644 index 0000000..13d7c9f --- /dev/null +++ b/RUBLIST.C @@ -0,0 +1,121 @@ +#include +#include +#include +struct node { + int num; + struct node * nextptr; +}*stnode; + +struct node *tail,*p,*q,*store,*cur; +void displayClList(int a); + void AddFront( int data) + { int d =1; + struct node *temp = (struct node*)malloc(sizeof(struct node)); + temp->num = data; + temp->nextptr = stnode; + cur=stnode; + while(cur->nextptr!=stnode) + { + cur=cur->nextptr; + } cur->nextptr=temp; + stnode=temp; + displayClList(d); + } + +void ClListcreation(int n); +void ClListDeleteLastNode(); + + +int main() +{ + int n,num1,a,pos,c; + stnode = NULL; + clrscr(); + printf("\n\n Circular Linked List : Delete node at the end of a circular linked list :\n"); + printf("--------------------------------------------------------------------------------\n"); + + printf(" Input the number of nodes : "); + scanf("%d", &n); + ClListcreation(n); + a=1; + displayClList(a); + tail=stnode; + //ClListDeleteLastNode(); + //a=2; +printf("\n Enter new data = "); +scanf("%d",&c); + AddFront(c); +displayClList(a); + getch(); + return 0; +} + +void ClListcreation(int n) +{ + int i, num; + struct node *preptr, *newnode; + + if(n >= 1) + { tail = (struct node *)malloc(sizeof(struct node)); + stnode = (struct node *)malloc(sizeof(struct node)); + tail=stnode; + printf(" Input data for node 1 : "); + scanf("%d", &num); + stnode->num = num; + stnode->nextptr = NULL; + preptr = stnode; + for(i=2; i<=n; i++) + { + newnode = (struct node *)malloc(sizeof(struct node)); + printf(" Input data for node %d : ", i); + scanf("%d", &num); + newnode->num = num; + newnode->nextptr = NULL; // next address of new node set as NULL + preptr->nextptr = newnode; // previous node is linking with new node + preptr = newnode; // previous node is advanced + } + preptr->nextptr = stnode; //last node is linking with first node + } +} + +void ClListDeleteLastNode() +{ + p=stnode; + while(p->nextptr!=stnode) + { + q=p; + p=p->nextptr; + } + q->nextptr=stnode; + printf("\n The deleted node is : %d",p->num); + free(p); +} + +void displayClList(int m) +{ + struct node *tmp; + int n = 1; + + if(stnode == NULL) + { + printf(" No data found in the List yet."); + } + else + { + tmp = stnode; + if (m==1) + { + printf("\n Data entered in the list are :\n"); + } + else + { + printf("\n After deletion the new list are :\n"); + } + do { + printf(" Data %d = %d\n", n, tmp->num); + + tmp = tmp->nextptr; + n++; + }while(tmp != stnode); + } +} diff --git a/RUBYSTAC.C b/RUBYSTAC.C new file mode 100644 index 0000000..1cd271c --- /dev/null +++ b/RUBYSTAC.C @@ -0,0 +1,85 @@ +//stack +#include +#include +#include +struct stack +{ int bno; + char bnm[25]; + struct stack *next; +}; +struct stack *top,*newptr,*ptr; +void display() +{ if(top==NULL) + printf("\n Stack is empty "); + else + { printf("\n Stack is "); + ptr=top; + printf("\n -> "); + while(ptr) + { printf("%d",ptr->bno); + printf("%s ",ptr->bnm); + printf("\n "); + ptr=ptr->next; + } + } +} +void push() +{ newptr = (struct stack*)malloc(sizeof(struct stack)); + if(newptr==NULL) + { printf("\n Memory overflow "); + } + else + { printf("\n Enter book number = "); + scanf("%d",&newptr->bno); + printf("\n Enter book name = "); + scanf("%s",&newptr->bnm); + newptr->next=NULL; + if(top==NULL) + top=newptr; + else + { newptr->next=top; + top=newptr; + } + printf("\n Stack after push : \n "); + display(); + } +} +void pop() +{ if(top==NULL) + printf("\n Memory underflow stack is empty "); + else + { ptr=top; + top=top->next; + free(ptr); + printf("\n Stack after pop : \n "); + display(); + } +} +void main() +{ int ch; + top=NULL; + + do + { clrscr(); + printf("\n MENU "); + printf("\n 1.Push in linked list stack "); + printf("\n 2.Pop in linked list stack "); + printf("\n 3. Traverse the stack "); + printf("\n 4. Exit "); + printf("\n Enter choice (1-4) = "); + scanf("%d",&ch); + switch(ch) + { case 1 : push(); + break; + case 2 : pop(); + break; + case 3 : display(); + break; + case 4 : printf("\n Terminating "); + break; + default:printf("\n Wrong Choice "); + break; + } + getch(); + }while(ch!=4); +} diff --git a/Swapping of elements using Call by Reference b/Swapping of elements using Call by Reference new file mode 100644 index 0000000..fb3b190 --- /dev/null +++ b/Swapping of elements using Call by Reference @@ -0,0 +1,28 @@ +#include + +void swap(int*, int*); + +int main() +{ + int x, y; + + printf("Enter the value of x and y\n"); + scanf("%d%d",&x,&y); + + printf("Before Swapping\nx = %d\ny = %d\n", x, y); + + swap(&x, &y); + + printf("After Swapping\nx = %d\ny = %d\n", x, y); + + return 0; +} + +void swap(int *a, int *b) +{ + int temp; + + temp = *b; + *b = *a; + *a = temp; +} diff --git a/base.py b/base.py index 6b26b6d..f2cb8b9 100644 --- a/base.py +++ b/base.py @@ -1,4 +1,18 @@ #Code File +void x() +{cout<<"Hello World"; +} + +def helloworld(): + + return "Hello World" + print('hello world') + + +def printing(): + print("hello world") + + #Code File def printing(): print("hello world") diff --git a/main.c b/main.c new file mode 100644 index 0000000..01ee4b3 --- /dev/null +++ b/main.c @@ -0,0 +1,83 @@ +// +// main.c +// Ps +// +// Created by Apple on 18/08/19. +// Copyright © 2019 Apple. All rights reserved. +// + +#include +#include + + + +struct Node +{ + int data; + struct Node *next; +}*front = NULL,*rear = NULL; + +void insert(int); +void delete(); +void display(); + +int main() +{ + int choice, value; + + printf("\n:: Queue Implementation using Linked List ::\n"); + while(1){ + printf("\n****** MENU ******\n"); + printf("1. Insert\n2. Delete\n3. Display\n4. Exit\n"); + printf("Enter your choice: "); + scanf("%d",&choice); + switch(choice){ + case 1: printf("Enter the value to be insert: "); + scanf("%d", &value); + insert(value); + break; + case 2: delete(); break; + case 3: display(); break; + case 4: exit(0); + default: printf("\nWrong selection!!! Please try again!!!\n"); + } + } +} +void insert(int value) +{ + struct Node *newNode; + newNode = (struct Node*)malloc(sizeof(struct Node)); + newNode->data = value; + newNode -> next = NULL; + if(front == NULL) + front = rear = newNode; + else{ + rear -> next = newNode; + rear = newNode; + } + printf("\nInsertion is Success!!!\n"); +} +void delete() +{ + if(front == NULL) + printf("\nQueue is Empty!!!\n"); + else{ + struct Node *temp = front; + front = front -> next; + printf("\nDeleted element: %d\n", temp->data); + + } +} +void display() +{ + if(front == NULL) + printf("\nQueue is Empty!!!\n"); + else{ + struct Node *temp = front; + while(temp->next != NULL){ + printf("%d--->",temp->data); + temp = temp -> next; + } + printf("%d--->NULL\n",temp->data); + } +} diff --git a/multiplicationofnumbers.cpp b/multiplicationofnumbers.cpp new file mode 100644 index 0000000..6425086 --- /dev/null +++ b/multiplicationofnumbers.cpp @@ -0,0 +1,8 @@ +int main() +{ +int a,b,ans; +a=9; +b=34; +ans=a*b; +cout<