Question about Compilers & Programming Tools

5 Answers

Source code for stack using arrays in c++

I want a stack program using arrays
with menu options
push,pop,display ,exit

Posted by on

  • 1 more comment 
  • yhael Feb 27, 2009

    i want a stack program using arrays
    with menu options
    push,pop,display ,exit

  • Carlos Galvez May 11, 2010

    Which language are we dealing with here?

  • Dave Harris
    Dave Harris May 11, 2010

    What is it you're trying to stack?

    What do you want to display things on?

    Is this a homework/coursework assignment ;-?


×

5 Answers

  • Level 1:

    An expert who has achieved level 1.

    Corporal:

    An expert that has over 10 points.

    Mayor:

    An expert whose answer got voted for 2 times.

    Problem Solver:

    An expert who has answered 5 questions.

  • Contributor
  • 8 Answers

Stack in c using arrays
/* Program of stack using array*/
#include

Posted on Sep 01, 2010

  • Level 1:

    An expert who has achieved level 1.

    Mayor:

    An expert whose answer got voted for 2 times.

  • Contributor
  • 1 Answer

Make a stack program C that
CreateStack
FullStack
EmptyStack
Push
Pop
Peek

Posted on Apr 26, 2010

  • Level 1:

    An expert who has achieved level 1.

    Mayor:

    An expert whose answer got voted for 2 times.

  • Contributor
  • 1 Answer

Visit

http://www.cppforschool.com/tutorial/dynamic-stack.html

Posted on Jan 29, 2011

  • Level 1:

    An expert who has achieved level 1.

  • Contributor
  • 1 Answer

I want to know push and pop

Posted on Aug 28, 2012

  • Level 1:

    An expert who has achieved level 1.

  • Contributor
  • 1 Answer

/**************** CProgram For Impelmetation Of Stack ********************/#define MAXSIZE 10struct st{int top;int stack[MAXSIZE];};struct st s;int empty(void);int full(void);void push(void);void pop(void);void display(void);void main(){char ans;int ch;do{clrscr();printf("********StackProgram**********\n");printf("1.PUSH\n");printf("2.POP\n");printf("3.DISPLAY\n");printf("4.QUIT\n");printf("EnterYour Choice : ");scanf("%d",&ch);switch(ch){case 1:push();break;case 2:pop();break;case 3:display();break;case 4:exit(1);break;default:printf("INVALIDCHOICE!!!!!!!!!!!!!!!!\n");break;}printf("Want ToGo To The Main Menu[y/n]");flushall();ans = getch();}while(ans == 'y' ans== 'Y');printf("\nPressAny Key To Exit");getch();}int full(void){if (s.top == MAXSIZE)return(1);elsereturn(0);}int empty(void){if (s.top == 0)return(1);elsereturn(0);}void push(void){char ch;int x;do{if(full() == 1){printf("\nStackFull\n");break;}else{s.top = s.top + 1;printf("\nEnterAn Element To Be Pushed: ");scanf("%d",&x);s.stack[s.top] = x;}printf("\nDo YouWant To Push More Elements[y/n]");flushall();ch = getch();}while(ch == 'y' ch =='Y');}void pop(void){char ch;do{if(empty() == 1){printf("\nStackEmpty\n");break;}else{printf("\n%d hasbeen popped !",s.stack[s.top]);s.top = s.top - 1;}printf("\nDo youWant To Pop Out More?[y/n]");flushall();ch = getch();}while(ch == 'Y' ch =='y');}void display(void){int i;clrscr();if(empty() == 1)printf("\nStackEmpty!!!");else{printf("DisplayingStack............\n");for(i = s.top;i>0;i--)printf("%d",s.stack[i]);}}/**************OUTPUT *********************StackProgram**********1. PUSH2. POP3. DISPLAY4. QUITEnter Your Choice : 1Enter An Element ToBe Pushed : 1Do YOu Want To PushMore Elements [y\n] yEnter An Element ToBe Pushed : 2Do YOu Want To PushMore Elements [y\n] yEnter An Element ToBe Pushed : 3Do YOu Want To PushMore Elements [y\n] yEnter An Element ToBe Pushed : 4Do YOu Want To PushMore Elements [y\n] yEnter An Element ToBe Pushed : 5Do YOu Want To PushMore Elements [y\n] nWant To Go Main Menu?[y\n] y********StackProgram**********1. PUSH2. POP3. DISPLAY4. QUITEnter Your Choice : 3DisplayingStack......54321Want To Go Main Menu?[y\n] y********StackProgram**********1. PUSH2. POP3. DISPLAY4. QUITEnter Your Choice : 25 Has Been Popped!Do You Want To PopMore? [y\n] y4 Has Been Popped!Do You Want To PopMore? [y\n] nWant To Go Main Menu?[y\n] y********StackProgram**********1. PUSH2. POP3. DISPLAY4. QUITEnter Your Choice : 3DisplayingStack.........321Want To Go Main Menu?[y\n] y********StackProgram**********1. PUSH2. POP3. DISPLAY4. QUITEnter Your Choice : 4*/

Posted on Nov 13, 2011

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

1 Answer

Twenty-five numbers are entered from the keyboard into an array.The number to be searched is entered through the keyboard by user.Write a program to find if the number to be searched is present in the...


pseudo is
-> integer type count =0;
->Take input from user 'Number'
->loop from 0th to 24th element
->Compare each element with user entered number and if it matches then do count++.
finally display the count.

Jul 29, 2010 | Advanced Graphics Programming Using OpenGL...

1 Answer

How to convert infix to postfix using stacks in java programming?


u can try the follwing coding
import java.io.*;
import java.util.*;
//begin coding for the stack interface
interface Stack<E>
{
public boolean isEmpty();//tests is current stack is empty. Returns true if so, and false if not.
public E top() throws StackException;//retrieves value at the top of the stack. Stack cannot be empty.
public void push(E value) throws StackException;//pushes a value on the top of the stack.
public void pop() throws StackException;//removes a value from the top of the stack. Stack cannot be empty.
}//terminates coding of Stack interface

//begin coding for the objArrayStack class
class objArrayStack<E> implements Stack<E>
{
//constructor
public objArrayStack()
{
topValue=-1;
}//terminates constructor
public void push(E value)throws StackException
{
if(topValue<ArraySize-1)//currrent stack is not full
{
++topValue;
Info[topValue]=value;
}//terminates if
else //current stack is full
throw new StackException("Error: Overflow");
}//terminates push method
public void pop() throws StackException
{
if(!isEmpty())//current stack is not empty
--topValue;
else //stack is empty
throw new StackException("Error: Underflow");
}//terminates pop method
public boolean isEmpty()
{
return topValue==-1;
}//terminates isEmpty method
public E top() throws StackException
{
if(!isEmpty())//stack is not empty
return (E)Info[topValue];
else //stack is empty
throw new StackException("Error: Underflow");
}//terminates top method
//declare instance variables
final int ArraySize=10;
private Object Info[]=new Object[ArraySize];
private int topValue;

//begins coding for the StackException class
class StackException extends RuntimeException
{
//constructor
public StackException(String str)
{
super(str);
}//terminates text of constructor
}//terminates text of StackException class

//method to convert from infix to postfix notation
public static String InToPost(String infixString)
{
//operator stack initialized
objArrayStack<Character> operatorStack = new objArrayStack<Character>();
//postfix string initialized as empty
String postfixString = " ";
//scan infix string and take appropriate action
for(int index = 0; index < infixString.length(); ++index)
{
char chValue = infixString.charAt(index);
if(chValue == '(')
operatorStack.push('(');
else if(chValue == ')')
{
Character oper = operatorStack.top();
while(!(oper.equals('(')) && !(operatorStack.isEmpty()))
{
postfixString += oper.charValue();
operatorStack.pop();
oper = operatorStack.top();
}//end while loop
operatorStack.pop();
}//end else if
else if(chValue == '+' || chValue == '-')
{
if(operatorStack.isEmpty()) //operatorStack is empty
operatorStack.push(chValue);
else //current operatorStack is not empty
{
Character oper = operatorStack.top();
while(!(operatorStack.isEmpty() || oper.equals(new Character('(')) || oper.equals(new Character(')'))))
{
operatorStack.pop();
postfixString += oper.charValue();
}//ends while loop
operatorStack.push(chValue);
}//end else
}//end else if
else if(chValue == '*' || chValue == '/')
{
if(operatorStack.isEmpty())
operatorStack.push(chValue);
else
{
Character oper = operatorStack.top();
while(!oper.equals(new Character('+')) && !oper.equals(new Character('-')) && !operatorStack.isEmpty())
{
operatorStack.pop();
postfixString += oper.charValue();
}//end while loop
operatorStack.push(chValue);
}//end else
}//end else if
else
postfixString += chValue;
}//end for loop
while(!operatorStack.isEmpty())
{
Character oper = operatorStack.top();
if(!oper.equals(new Character('(')))
{
operatorStack.pop();
postfixString += oper.charValue();
}//end if
}//end while
return postfixString ;
}//terminates text of InToPost method

public static void main(String[]args)
{
objArrayStack mystack = new objArrayStack();
System.out.println("Enter a string");
Scanner scan = new Scanner(System.in);
scan.nextLine();
String str = scan.nextLine();
InToPost(str);
}//terminates text of main method
}//terminates text of objArrayStack class

Mar 16, 2010 | Sun Java Programming Language (cdj-275)

1 Answer

What problems come in project of library management


stack mismatch, over flow, memory dispatch, dynamic array alloaction, pointer conversion, type mismatch are some of the problem u experience in all projects

Oct 27, 2009 | ArcMedia JavaScript Source Code 3000 Pro...

1 Answer

Don't Send error while running a vc++ Application


If u use arrays and/or stacks make sure u access and write properly

Jun 19, 2009 | Compilers & Programming Tools

1 Answer

Source code of a program


import java.util.*;
public class StringReverse {
  public static void main(String[] argv) {
    //+
    String s = "Support Tech Problem";

    // Put it in the stack frontwards
    Stack myStack = new Stack();
    StringTokenizer st = new StringTokenizer(s);
    while (st.hasMoreTokens()) myStack.push(st.nextElement());

    // Print the stack backwards
    System.out.print('"' + s + '"' + " backwards by word is:\n\t\"");
    while (!myStack.empty()) { 
      System.out.print(myStack.pop());
      System.out.print(' ');
    }
    System.out.println('"');
    //-
  }
}

Apr 07, 2009 | ArcMedia JavaScript Source Code 3000 Pro...

1 Answer

A Program using an array that culculates the sum and average of the five input values?


Hi,
I am writing in C code here
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,sum=0;
float avg=0;
printf("enter the five values");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
for(i=0;i<5;i++)
sum+=a[i];
printf("Sum=%d",sum);
avg=sum/5;
printf("Average=%f",avg);
getch();
}

Mar 18, 2009 | ArcMedia JavaScript Source Code 3000 Pro...

2 Answers

Source code for word count


Haha, i wrote one of thee a while ago for a competition. You need to us e the char at function mate :D
Inside a for loop
Ill havea look for you though :D

Sep 09, 2008 | ArcMedia JavaScript Source Code 3000 Pro...

2 Answers

C++ programs


An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier
Initializing arrays. When declaring a regular array of local scope (within a function, for example), if we do not specify otherwise, its elements will not be initialized to any value by default, so their content will be undetermined until we store some value in them. The elements of global and static arrays, on the other hand, are automatically initialized with their default values, which for all fundamental types this means they are filled with zeros
include <iostream>
using namespace std;

int billy [] = {16, 2, 77, 40, 12071};
int n, result=0;

int main ()
{
for ( n=0 ; n<5 ; n++ )
{
result += billy[n];
}
cout << result;
return 0;
}
multidimensional array pseudo-multidimensional array #define WIDTH 5 #define HEIGHT 3 int jimmy [HEIGHT][WIDTH]; int n,m; int main () { for (n=0;n<HEIGHT;n++) for (m=0;m<WIDTH;m++) { jimmy[n][m]=(n+1)*(m+1); } return 0; } #define WIDTH 5 #define HEIGHT 3 int jimmy [HEIGHT * WIDTH]; int n,m; int main () { for (n=0;n<HEIGHT;n++) for (m=0;m<WIDTH;m++) { jimmy[n*WIDTH+m]=(n+1)*(m+1); } return 0; }
and now for trignometry
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
int factorial(int);
int n = 3, i = 1;
double x, x2, b, PI, r;
char choice;
//r = x * (PI / 180)

cout<<"Please enter an angle value => ";
cin>>x;
cout<<"Is the angle value in Degree or Radian?"<<endl;
cout<<"Type D if its in degree "<<endl;
cout<<"Type R if its in radian "<<endl;
cin>>choice;


if((choice = 'R')||(choice = 'r'))
do{
i++; n = 3; x2 = 0; b = x2;
{
if(i == 1)
x2 = x - (pow(x,n) /factorial(n));
n = n + 2;
};
else
{
x2 = (x2 + ((pow(x,n)) /(factorial(n))) - (pow(x,n+2)) / (factorial(n+2)));
n = n + 4;
}


}while(abs(b - x2) > 0.000001);
else
//convert it to r

r = x * PI /180;

//cout<<"error occured/n";
cout<<"sin(x) = "<<x2<<endl;

return 0;
}

Mar 24, 2008 | ArcMedia JavaScript Source Code 3000 Pro...

Not finding what you are looking for?
Compilers & Programming Tools Logo

Related Topics:

2,789 people viewed this question

Ask a Question

Usually answered in minutes!

Top Compilers & Programming Tools Experts

Robin Hill
Robin Hill

Level 3 Expert

1251 Answers

Fred Block
Fred Block

Level 2 Expert

289 Answers

Les Dickinson
Les Dickinson

Level 3 Expert

18298 Answers

Are you a Compiler and Programming Tool Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...