c program for implement a stack using two queue First push the given elements in stack1... then pop those elements and push them in 2nd stack... now pop the elements from this stack... thus implemented queue
#include < stdio.h >
#include < conio.h >
#define MAX 10
int stack[MAX],top;
void main()
{
char ch;
int choice,item;
void display();
int pop();
void push(int);
clrscr();
top=-1;
do
{
printf("1.Insertion");
printf("\n2.Deletion");
printf("\n3.Display");
printf("\nEnter your choice(1-3):");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("\nEnter the item to be inserted:");
scanf("%d",&item);
push(item);
display();
break;
case 2: item=pop();
printf("\nThe item deleted is %d",item);
display();
break;
case 3: display();
break;
default:printf("Wrong choice");
break;
}
printf("\nDo you want to continue(y/n):");
fflush(stdin);
scanf("%c",&ch);
}while(ch=='y' ch=='Y');
getch();
}
void push(int item)
{
if(top==MAX-1)
{
printf("Stack Overflow");
return;
}
top=top+1;
stack[top]=item;
}
int pop()
{
int t;
if(top==-1)
{
printf("Stack Underflow");
return -1;
}
t=stack[top];
top=top-1;
return t;
}
void display()
{
int i;
printf("\nThe Stack elements are:");
for(i=0;i < =top;i++)
printf("%5d",stack[i]);
}
//Class for Stack - Linked List implementation Class Stack { public: STACKPTR *stackptr; Stack(); ~Stack(); Protected: struct Element { int data; struct Element *next }; typedef struct Element *STACKPTR; Public: bool push(int data); bool pop(int* data); }; Stack::Stack() { stackptr = NULL; } Stack::~Stack() { while(stackptr) //delete all elements { STACKPTR temp = stackptr->next; delete stackptr; stackptr = temp } stackptr = NULL; } bool Stack::Push(int data) { //add nodes in front of Linked list STACKPTR newNode = new Element; newNode->data = data; if(!newNode) return false; newNode->next = stackptr; stackptr = newNode; return true; } bool Stack::pop(int* data) { STACKPTR temp; if(!stackptr) //stack is empty return false; temp = stackptr; *data = stackptr->data; stackptr = stackptr->next; delete temp; retrun true; }
However if, while trying to do your assignment, you find a specific problem that you need help with, WikiAnswers will help you with these specific questions (e.g is this 'xxxxx' C++ statement correct).
Answervoid CreateStack_Core (your_stack_type &stack, int nhas, int nreq){
if (nhas AddElement (stack); CreateStack_Core (stack, nhas+1, nreq); } } void CreateStack (your_stack_type &stack, int nreq) { CreateEmptyStack (stack); CreateStack_Core (stack, 0, nreq); }
Supposing you have a class named foo and you wish to create a stack of foo objects using pointers, you would use the following declaration:
std::stack<std::unique<foo>> my_stack;
Note that the stack takes ownership of the pointer, thus when you pop a foo from the stack, the object is automatically destroyed. Therefore you should only pop the top stack element when you are actually done with it.
If you wish to use shared ownership, use std::shared_ptr instead. The same rule applies, but objects are only destroyed after a pop if there are no other references to that object.
/* Static implementation of stack
using Array and local variables
and structure*/
#include<conio.h>
#include<stdio.h>
#define MAX 5
struct stack
{
int arr[ MAX ]; //array to be treated as stack
int top;
};
typedef struct stack stack;
void push( stack *, int );
int pop( stack * );
void display( stack );
void main()
{
stack stk;
int val;
int choice;
//initialization (initialize stack to be empty)
stk.top = -1;
clrscr();
do
{
clrscr();printf("\n**** Stack Opertions ****");printf( "\n1) Add Element" );printf( "\n2) Delete Element" );printf( "\n3) Display" );printf( "\n4) Exit" );printf("\n\nPlease enter your choice(1/2/3/4):");scanf("%d", &choice );switch( choice ){case 1 :printf("\nPlease enter the element"\" to be added : ");scanf("%d", &val );push( &stk, val );break;case 2 :val = pop( &stk );if( val != -9999 ){printf("\nThe element deleted"\" is %d", val );}break;case 3 :display( stk );break;case 4 :printf("\nFinished with stack operations : ");break;default:printf("\nIncorrect choice!!!! ");}printf("\nPress any key to continue : ");getch();}while( choice != 4 );return;
}
void push( stack *sptr, int val )
{
// CHECKING IF THE STACK IS FULLif( sptr->top -1 )
{
printf("\nThe stack is empty!!!");}
else
{
printf("\t%d", stk.arr[ stk.top ] ) ;}
return;
}
*/
Yes, please do.
Write and run a client and a server program in C-language using UDP
A stack is implicitly sorted by hierarchical nested order. It does not make sense to sort a stack. Do you mean a list? If so, please ask the question again.
It is not possible to write a code to POP from the stack when there is no your stack implementation information.Because of that I am going to talk more about Stack in computer architecture and there will be additional link to specific examples(-e).In x86 architecture there is three registers (BP, SP and SS) which are connected with stack and only SP and SS is needed.SS - Stack Segment (base register);SP - Stack Pointer (offset);This is how the POP instruction works:# operand = [SS:SP] (top of the stack) # SP = SP + 2; (change SP to point to new top element)
Yes.
JavaScript is one program that has been written in C to implement the Apriori algorithm. There are also several other known programs available on the Internet that implement it as well.
In order to write a program to convert stack into queue using c language you must be able to identify the proper program. Having a special certification in programing will be beneficial as well to make sure you recognize the proper queues for the programs.
int top=-1; int stack[10];
Write and run a client and a server program in C-language using UDP
write an assembly language program to find sum of N numbers
A stack is implicitly sorted by hierarchical nested order. It does not make sense to sort a stack. Do you mean a list? If so, please ask the question again.
write a program to print A to Z on screen in c?
Yes.
It is not possible to write a code to POP from the stack when there is no your stack implementation information.Because of that I am going to talk more about Stack in computer architecture and there will be additional link to specific examples(-e).In x86 architecture there is three registers (BP, SP and SS) which are connected with stack and only SP and SS is needed.SS - Stack Segment (base register);SP - Stack Pointer (offset);This is how the POP instruction works:# operand = [SS:SP] (top of the stack) # SP = SP + 2; (change SP to point to new top element)
JavaScript is one program that has been written in C to implement the Apriori algorithm. There are also several other known programs available on the Internet that implement it as well.
How to write the program un Assembly language to set a password for personal computers?
AdvantageThe only advantage is that program of machine language run very fast because no translation program is required for the CPU.DisadvantagesIt is very difficult to program in machine language. The programmer has to know details of hardware to write program.The programmer has to remember a lot of codes to write a program which results in program errors.It is difficult to debug the program.
write program to concatenating two sting in 8086 assembly language