answersLogoWhite

0

Abey kaminey, agar main jaanta to tere se puchhne jata.

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering

Program for dequeue in data structure?

Display function in de queue void display() { int i; if((front == -1) (front==rear+1)) printf("\n\nQueue is empty.\n"); else { printf("\n\n"); for(i=front; i<=rear; i++) printf("\t%d",queue[i]); } }


Design stack and queue classes with necessary exception handling?

#include<iostream.h> #include<process.h> #define SIZE 10 class Stack { private: int a[SIZE]; int top; public: Stack(); void push(int); int pop(); int isEmpty(); int isFull(); void display(); }; Stack::Stack() { top=0; } int Stack::isEmpty() { return (top==0?1:0); } int Stack::isFull() { return(top==SIZE?1:0); } void Stack::push(int i) { try { if(isFull()) { throw "Full"; } else { a[top]=i; top++; } } catch(char *msg) { cout<<msg; } } int Stack::pop() { try { if(isEmpty()) { throw "Empty"; } else { return(a[--top]); } } catch(char *msg) { cout<<msg; } return 0; } void Stack::display() { if(!isEmpty()) { for(int i=top-1;i>=0;i--) cout<<a[i]<<endl; } } int main() { Stack s; int ch=1; int num; while(ch!=0) { cout<<"1. push"<<endl <<"2. pop"<<endl <<"3. display"<<endl <<"0. Exit"<<endl; cout<<"Enter ur choice :"; cin>>ch; switch(ch) { case 0: exit(1); case 1: cout<<"Enter the number to push"; cin>>num; s.push(num); break; case 2: cout<<"a number was popped from the stack"<<endl; s.pop(); break; case 3: cout<<"The numbers are"<<endl; s.display(); break; default: cout<<"try again"; } } return 0; } #include<iostream.h> #define SIZE 10 class Queue { private: int rear; int front; int s[SIZE]; public: Queue() { front=0; rear=-1; } void insert(int); void del(); int isEmpty(); int isFull(); void display(); }; int Queue::isEmpty() { return(front>rear?1:0); } int Queue::isFull() { return(rear==SIZE?1:0); } void Queue::insert(int item) { try { if(isFull()) { throw "Full"; } else { rear=rear+1; s[rear]=item; } } catch(char *msg) { cout<<msg; } } void Queue::del() { int item; try { if(isEmpty()) { throw "Empty"; } else { item=s[front]; front=front+1; cout<<"\n DELETED ELEMENT IS %d\n\n"<<item; } } catch(char *msg) { cout<<msg; } } void Queue::display() { cout<<"\n"; for(int i=front;i<=rear;i++) { cout<<s[i]<<"\t"; } } int main() { int ch; Queue q; int item; do { cout<<"\n\n1.INSERTION \n"; cout<<"2.DELETION \n"; cout<<"3.EXIT \n"; cout<<"\nENTER YOUR CHOICE : "; cin>>ch; switch(ch) { case 1: cout<<"\n\t INSERTION \n"; cout<<"\nENTER AN ELEMENT : "; cin>>item; q.insert(item); q.display(); break; case 2: cout<<"\n\t DELETION \n"; q.del(); q.display(); break; } }while(ch!=3); return 0; }


What are the various operations that can be performed on a queue?

In queue insertion takes place on rear end and deletion takes place on front end. INSERTION(QUEUE,N,FRONT,REAR,ITEM) :QUEUE is the name of a array on which we are implementing the queue having size N. view comlete ans at http://mcabcanotes.in/algorithm-to-perform-insertion-and-deletion-in-a-queue/


What are the differences between Stack Arrays Queues tabular Form?

Array: A contiguous block of memory. When you know the position of the nth element of an array, you know that the elements at n+1 and n-1 are very nearby in memory. Stack: A first-in-last-out data structure. A stack can be backed by most generic data structures (even arrays), but the linked-list type seems to be most common. You can think of a stack like a stack of playing cards. You can put a bunch of cards facedown on a table, and when you draw from the stack, you can only take the topmost card. The "first-in-last-out" means that the card that you put down first can't be removed until you remove all cards on top of it. Queue: A first-in-first-out data structure. Very similar to a stack in regards to data storage. Think of this one like a line of people. The first person in the line is the first one to get out of it, and everyone behind them has to wait their turn.


Implement a class stack which simulates the operations of the stack allowing LIFO operationsAlso implement push and pop operations for the stack?

/* C program to implement stack. Stack is a LIFO data strcuture LIFO - Last in First Out Perform PUSH(insert operation), POP(Delete operation) and Display stack */#include #include #define MAXSIZE 5struct stack /* Structure definition for stack */{int stk[MAXSIZE];int top;};typedef struct stack STACK;STACK s;/* Function declaration/Prototype*/void push (void);int pop(void);void display (void);void main (){int choice;int option = 1;clrscr ();s.top = -1;printf ("STACK OPERATION\n");while (option){printf ("--------------\n");printf (" 1 -> PUSH \n");printf (" 2 -> POP \n");printf (" 3 -> DISPLAY \n");printf (" 4 -> EXIT \n");printf ("--------------\n");printf ("Enter your choice\n");scanf ("%d", &choice);switch (choice){case 1: push();break;case 2: pop();break;case 3: display();break;case 4: return;}fflush (stdin);printf ("Do you want to continue(Type 0 or 1)?\n");scanf ("%d", &option);}}/*Function to add an element to the stack*/void push (){int num;if (s.top -1){printf ("Stack is empty\n");return;}else{printf ("\nThe status of the stack is\n");for (i = s.top; i >= 0; i-){printf ("%d\n", s.stk[i]);}}printf ("\n");}byankit shukla

Related Questions

Program for dequeue in data structure?

Display function in de queue void display() { int i; if((front == -1) (front==rear+1)) printf("\n\nQueue is empty.\n"); else { printf("\n\n"); for(i=front; i<=rear; i++) printf("\t%d",queue[i]); } }


What is the time complexity for inserting an element into a priority queue?

The time complexity for inserting an element into a priority queue is O(log n), where n is the number of elements in the priority queue.


What is the time complexity of inserting an element into a priority queue?

The time complexity of inserting an element into a priority queue is O(log n), where n is the number of elements in the priority queue.


What is the time complexity of popping an element from a priority queue?

The time complexity of popping an element from a priority queue is O(log n), where n is the number of elements in the priority queue.


Similarities between the U.S.S Maine and the Lusitania?

the n iojrode


Design stack and queue classes with necessary exception handling?

#include<iostream.h> #include<process.h> #define SIZE 10 class Stack { private: int a[SIZE]; int top; public: Stack(); void push(int); int pop(); int isEmpty(); int isFull(); void display(); }; Stack::Stack() { top=0; } int Stack::isEmpty() { return (top==0?1:0); } int Stack::isFull() { return(top==SIZE?1:0); } void Stack::push(int i) { try { if(isFull()) { throw "Full"; } else { a[top]=i; top++; } } catch(char *msg) { cout<<msg; } } int Stack::pop() { try { if(isEmpty()) { throw "Empty"; } else { return(a[--top]); } } catch(char *msg) { cout<<msg; } return 0; } void Stack::display() { if(!isEmpty()) { for(int i=top-1;i>=0;i--) cout<<a[i]<<endl; } } int main() { Stack s; int ch=1; int num; while(ch!=0) { cout<<"1. push"<<endl <<"2. pop"<<endl <<"3. display"<<endl <<"0. Exit"<<endl; cout<<"Enter ur choice :"; cin>>ch; switch(ch) { case 0: exit(1); case 1: cout<<"Enter the number to push"; cin>>num; s.push(num); break; case 2: cout<<"a number was popped from the stack"<<endl; s.pop(); break; case 3: cout<<"The numbers are"<<endl; s.display(); break; default: cout<<"try again"; } } return 0; } #include<iostream.h> #define SIZE 10 class Queue { private: int rear; int front; int s[SIZE]; public: Queue() { front=0; rear=-1; } void insert(int); void del(); int isEmpty(); int isFull(); void display(); }; int Queue::isEmpty() { return(front>rear?1:0); } int Queue::isFull() { return(rear==SIZE?1:0); } void Queue::insert(int item) { try { if(isFull()) { throw "Full"; } else { rear=rear+1; s[rear]=item; } } catch(char *msg) { cout<<msg; } } void Queue::del() { int item; try { if(isEmpty()) { throw "Empty"; } else { item=s[front]; front=front+1; cout<<"\n DELETED ELEMENT IS %d\n\n"<<item; } } catch(char *msg) { cout<<msg; } } void Queue::display() { cout<<"\n"; for(int i=front;i<=rear;i++) { cout<<s[i]<<"\t"; } } int main() { int ch; Queue q; int item; do { cout<<"\n\n1.INSERTION \n"; cout<<"2.DELETION \n"; cout<<"3.EXIT \n"; cout<<"\nENTER YOUR CHOICE : "; cin>>ch; switch(ch) { case 1: cout<<"\n\t INSERTION \n"; cout<<"\nENTER AN ELEMENT : "; cin>>item; q.insert(item); q.display(); break; case 2: cout<<"\n\t DELETION \n"; q.del(); q.display(); break; } }while(ch!=3); return 0; }


Why did people frequently queue for food?

N


Explain how circular queue differs from linear queue?

Both linear and circular queues are constructed from nodes: struct node { T data; // the node's value (of type T) node* next; // refers to the next node in the sequence }; To implement a queue efficiently, we need to keep track of both the front and back of the queue. This is because all insertions occur at the back of the queue while all extractions occur at the front of the queue, and both operations must be performed in constant time. struct queue { node* head; // refers to the front of the queue node* tail; // refers to the back of the queue }; Initially, the queue is empty, so both the head and tail must be set to NULL. We use the following function to insert some data at the back of the queue: node* push (queue* q, T value) { node* n = malloc (sizeof (node)); n->data = value; n->next = NULL; if (q->tail == NULL) { q->head = n; q->tail = n; } else { q->tail->next = n; q->tail = n; } return n; } The following function extracts the head node: void pop (queue* q) { node* n = q->head; if (q->head) { q->head = q->head->next; // may be NULL if (!q->head) q->tail = NULL; } free n; } In a circular queue, we don't need to keep track of the head because tail->next always points to the head unless tail is NULL. So we can eliminate the head pointer from the queue structure: struct queue { node* tail; }; The insertion function therefore changes as follows: node* push (queue* q, T value) { node* n = malloc (sizeof (node)); n->data = value; if (q->tail == NULL) { n->next = n; q->tail = n; } else { n->next = q->tail->next; q->tail->next = n; q->tail = n; } return n; } And the extraction function changes as follows: void pop (queue* q) { if (q->tail == NULL) return; // empty list node* n = q->tail; if (q->tail == q->tail->next) // a list of one q->tail = NULL; else q->tail->next = q->tail->next->next; // adjust the head free n; }


What are the various operations that can be performed on a queue?

In queue insertion takes place on rear end and deletion takes place on front end. INSERTION(QUEUE,N,FRONT,REAR,ITEM) :QUEUE is the name of a array on which we are implementing the queue having size N. view comlete ans at http://mcabcanotes.in/algorithm-to-perform-insertion-and-deletion-in-a-queue/


What is circular queue operations circular queue?

A circular queue is similar to the normal queue with the difference that queue is circular queue ; that is pointer rear can point to beginning of the queue when it reaches at the end of the queue. Advantage of this type of queue is that empty location let due to deletion of elements using front pointer can again be filled using rear pointer. There are 2 conditions for queue full if queue is implemented using arrays. First condition is Front = 1 and Rear = N Second condition is Front = Rear + 1


What are the differences between Stack Arrays Queues tabular Form?

Array: A contiguous block of memory. When you know the position of the nth element of an array, you know that the elements at n+1 and n-1 are very nearby in memory. Stack: A first-in-last-out data structure. A stack can be backed by most generic data structures (even arrays), but the linked-list type seems to be most common. You can think of a stack like a stack of playing cards. You can put a bunch of cards facedown on a table, and when you draw from the stack, you can only take the topmost card. The "first-in-last-out" means that the card that you put down first can't be removed until you remove all cards on top of it. Queue: A first-in-first-out data structure. Very similar to a stack in regards to data storage. Think of this one like a line of people. The first person in the line is the first one to get out of it, and everyone behind them has to wait their turn.


Compare and contrast debt finance and equity finance?

similarities between equity n debt finance