Hello All, I am trying to implement a program that takes a prefix expression/string and converts it into a postfix string. I looked up the general algorithim for this converson and tried to implement it myself into this program. The following code is taken from my main java file. My output is displaying only the characters, not any of the operators in their correct place. Example, I have '*+abc' and the correct output should be 'ab+c*'. In this case my current output reads as 'abc'. Any help would be appreciated. Code is below: public class PreToPostPrac { public static void …

Member Avatar
Member Avatar
+0 forum 6

kindly someone to tell me one advantage of a stack backed by a dynamic array over a stack backed by a linked list and one advantage of a stack backed by a linked list over a stack backed by a dynamic array...

Member Avatar
Member Avatar
+0 forum 4

For example, How do I use this custom print method to display something in the main method? public static void print(Stack<String> myStack ) { int count = 1, sizeOfStack = myStack.size(); System.out.println("\nYour stack has size: " + myStack.size()); for (String myString : myStack) {System.out.print(count + ". " + myString); if(count!=sizeOfStack) System.out.print( " -> "); else System.out.print( " :Last"); count++;

Member Avatar
Member Avatar
+0 forum 5

Hello, I have to write a program which reads in a text file and sees the parsing symbols brackets, parentheses, and braces, and use stack implementation to have a balance symbol checker. My code compiles fine, but the output is strange, I know it has to do something with my for loop. Here is my code. import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; import java.util.Stack; public class Parentheses { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("C:/Users/Desktop/SourceCode.txt")); String input = null; StringBuilder sb = new StringBuilder(); while ((input = in.readLine()) != null) { sb.append(input); } …

Member Avatar
Member Avatar
+0 forum 3

cout << "Enter the filename " << endl; cin >> filename; inFile.open(filename); int length = 0; while (inFile) length++; IntStack stack(length); I keep getting an error and I have no idea why. Can someone explain what is going on with it? After I input the the filename, program terminates. My best guess is that my while loop is wrong or the file is empty...

Member Avatar
Member Avatar
+0 forum 8

#include <iostream> #include <iomanip> #include <string> #include <cstddef> #include <cstring> #include <fstream> #include "IntStack.h" using namespace std; int main() { char c; ifstream inFile; string filename; cout << "Enter the filename " << endl; cin >> filename; inFile.open(filename); IntStack stack(50); if (!inFile) //file could not be opened { cout << "File could now be opened. Program terminated." << endl; return 1; } else if (inFile) //could be open { while (inFile >> c) { if (c == '(') { if (!stack.isFull()) { stack.push(')'); } else { cout << "Sorry stack is full. " << endl; } } if (c == …

Member Avatar
Member Avatar
+0 forum 2

intstack.h cannot be changed class IntStack private: int *stackArray; // Pointer to the dynamically allocated stack array int stackSize; // The stack size int top; // Indicates the top of the stack public: // Constructor IntStack(int); // Destructor ~IntStack(); // Stack operations void push(int); int pop(); bool isFull() const; bool isEmpty() const; }; intstack.cpp cannot be changed using namespace std; IntStack::IntStack(int size) { stackArray = new int[size]; stackSize = size; top = -1; } IntStack::~IntStack() { delete [] stackArray; } void IntStack::push(int num) { assert (!isFull()); // will exit program if this happens top++; stackArray[top] = num; } int IntStack::pop() …

Member Avatar
Member Avatar
+0 forum 4

I'm running Exchange 2003 in my company; every 2 days it seems I get a call from a user stating a message is stuck in their outbox or they are not getting new mail. In all cases, restarting the information store and MTA stacks immediately clears the problem and gets mail coming and going again, for about another 2 days. Initially I thought maybe the exchange database was getting too large; we run a journal mailbox. I archived this out, and it still did it to me today. What needs to be done to correct this recurring issue? It has …

Member Avatar
+0 forum 0

I am working on a project for class. I have to write a program that reads in an infix expression and converts and it to postfix and evaluates it. Currently I have it to where I can convert an infix expression with no parentheses to postfix, but am having some trouble figuring out how to handle parentheses. import java.util.*; public class InfToPost { private Stack<String> convStack; private Stack<String> evalStack; private String infixExp; private String postfixExp = ""; private int temp; private int result; public InfToPost(String exp) { String str = ""; infixExp = exp; convStack = new Stack<String>(); evalStack = …

Member Avatar
+0 forum 0

Hi guys, Finally I've registered after being a very long visitor for this awesome community. I have this problem which consumed 2 days of my time trying to figure out how to solve it. And your help is needed guys. The problem says: Transfer elemenents from Stack1 to Stack2 , without using additional stack, recursion or arrays. Only using some additional variables. Stack2 should have the same order as in Stack1. what I understand from the word "Transfer" , this is going to be a desructive copy operation, because stack1 will be empty. My attempt does not work for any …

Member Avatar
Member Avatar
+0 forum 6

Hey so this is my code for checking for palindromes...it compiles fine, the problem is it doesnt work. Basically I converted the four sentences into strings without spaces or other characters and added them to a new string called newstr....i used the newstr to check for a palindrome in the latter part of my check palindrome method(after the first for loop), which works perfectly fine normally(when i dont have to remove spaces & non letter characters first)? By looking at my code do you see anything wrong or why it isnt finding the first 3 sentences as palindromes...thanks! import java.io.PrintWriter; …

Member Avatar
Member Avatar
+0 forum 3

I am having trouble figuring out how to get a user inputted value into a structure I've created to make a linked list of stacks. The structure and pointer info before main() are: struct inforec { int item; }; struct node; typedef node *PT_NODE; struct node { inforec info; PT_NODE next; }; typedef PT_NODE Stack; the function and prototype to get a value onto the stack are: int push(Stack &, inforec &); int push(Stack & S, inforec & item) { cout << "Enter a value to push" << endl; cout << " " << endl; cin >> item.item; //THIS IS …

Member Avatar
Member Avatar
+0 forum 1

I wanna convert an integer to a character then i will store it later to the index of a c-string...... something like... int res=123 then it will be putted in.... var[0] = 123 where in var is a cstring, and here 123 is now a char type..... here is what ive tried... [CODE]#include<iostream> using namespace std; int main() { int res=123; char buf[10]; itoa(res,buf,10); cout<<"new char: "<<buf[0]; system("pause>0"); } [/CODE] what happened is, only the 1 in 123 is being converted into char and stored to the cstring........ is there a way to avoid it? is the itoa function that …

Member Avatar
Member Avatar
+0 forum 1

I am struggling to write the push and pop functions for a stack of arrays. I know how to write the code to push single items unto a stack and pop them out. Some have suggested that I use an array of arrays (two-dimensional array) to load the array of integers unto the stack. The array is of length 7 and there are 25 of these arrays that need to be pushed onto a stack and then popped out. Usually, in my fillStack function, I read an element from a file and pass it to the push function. This time …

Member Avatar
Member Avatar
+0 forum 4

Hi all, I'm having a problem here!! I've attended a lecture on Implementation of stacks in c++ using arrays and it wasn't really hard to understand, but now I'm supposed to know how to Implement a stack using linked list, that's the problem. help please?:confused:

Member Avatar
Member Avatar
+0 forum 2

how many stacks does the kernel maintain/keep track of...say if there are 12 kernel threads and around 50 user processes??

Member Avatar
Member Avatar
+0 forum 3

Two things. First I need to resolve the linker errors I'm getting and I also need to learn how to create a text file in a C++ project file. I'm working on a stacks project with classes and I'm running into linker errors. Specifically it says: [B][Linker error] undefined reference to `Stack::Stack()'[/B]. I have a similar error for all the functions in my implementation file. I've tried several solutions and they've all failed. Please help. Thanks. The other problem. Since I was having the above problem, I decided to create a C++ project file. Usually, when I start working on …

Member Avatar
Member Avatar
+0 forum 12

I've searched all over, but Have not been able to find exactly what I need help on. I am creating a program that takes user input of a word and determines if it is a Palindrome or not....the catcher is I need to use stacks. They are confusing to me. I can write a simple Palindrome program without stacks, but not with. Any advice? This is what I have so far. [code=python] class Stack(): def __init__(self): self._items = [] def push(self,obj): self._items.append(obj) def pop(self): return self._items.pop() def peek(self): return self._items[-1] def isEmpty(self): return len(self._items)==0 def __len__(self): return len(self._items) def __str__(self): …

Member Avatar
Member Avatar
+0 forum 6

I have the following code for shell sort (recursive) given in the question where t[ ] is an array to be sorted, n=no of elements initially. h is any large no initially,say h>n. [CODE]void shell_rec(int t[],int n,int h) { int aux,i; if(h<=0) return; if(n>h) { shell_rec(t,n-h,h); if(t[n]<t[n-h]) { aux=t[n]; i=n; for(i=n;i>=h && aux<t[i-h];i=i-h) t[i]=t[i-h]; t[i]=aux; } } shell_rec(t,n,h/3); }[/CODE] removing tail recursion i get: [CODE]void shell_rec(int t[],int n,int h) { int aux,i; int j; for(j=h;j>0;j=j/3) { if(n>j) { shell_rec(t,n-j,j); if(t[n]<t[n-j]) { aux=t[n]; i=n; for(i=n;i>=j && aux<t[i-j];i=i-j) t[i]=t[i-j]; t[i]=aux; } } } }[/CODE] now i want to remove the recursion using …

Member Avatar
Member Avatar
+0 forum 6

can you tell me what is the equivalent of: [CODE]flushall()[/CODE] in Turbo c++? Thanks! Im having a problem because of that. Or, what is the header file of it? Thanks AGAIN :D

Member Avatar
Member Avatar
+0 forum 2

Hello i need help with the popping of stacks. i want to pop them all once i go into the Clear() method, but im having problems with the codings. here's my code: [CODE]import java.util.Stack; class InfixPost { static Stack inputStack; static String output = ""; public String infixToPostfix(String input) { inputStack = new Stack(); for (int i = 0; i < input.length(); i++) { char current = input.charAt(i); if (current == '+' || current == '-') { isOperator(current, 1); } else if (current == '*' || current == '/') { isOperator(current, 2); } else { output += current; } } …

Member Avatar
Member Avatar
-1 forum 3

i have to impplement a dynamic stack to create a program but when i try to compile my stack.c file(with gcc) I get a bunch of errors here are my files GLOBALS.h [CODE] #ifndef _globals #define _globals #define DATA( L ) ( ( L ) -> datapointer ) #define NEXT( L ) ( ( L ) -> next ) typedef enum { OK, ERROR } status ; typedef enum { FALSE = 0 , TRUE=1 } bool ; typedef void *generic_ptr ; #endif [/CODE] STACK.h [CODE] #ifndef _stack #define _stack #define STACKINCREMENT 100 #include "globals.h" typedef struct{ generic_ptr *base; generic_ptr …

Member Avatar
Member Avatar
+0 forum 5

Please could you show me how to use stakcs and queue to create a program that divided letters (a,b,c,d,e...x,y,z) by vowel and consonant letters.We have two stacks:in first should be vowel letters and in second consonant letters. Thanks in advance!

Member Avatar
Member Avatar
+0 forum 1

So i am suppose to write two methods called superPop and superPush. superPop() pops a StarLine object from the stack, sends it to System.out.print, and returns it. superPush() pushes a StarLine object onto the stack, sends it to System.out.print, and returns it. I am continuing to try new things but any help would be greatly appreciated. So far I have this written for this new class I am creating: [CODE]import java.io.*; import java.util.*; public class AllStars extends MyStack{ public StarLine superPop(){ if(empty()) { throw new EmptyStackException(); } System.out.print(); return; } public StarLine superPush(StarLine stars){ }[/CODE] Also here is the Starline …

Member Avatar
Member Avatar
+0 forum 1

The End.