you're not importing your Stack class so I assume it's in the same package, but is it actually there?
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
private Stack<Character> charStack = new Stack();
This is more of a question,since i don't really no myself. But it looks as if you are using syntax from c++. The< > symbols would indicate use of templates.
Since java does not support the use of templates this would be illegal?
http://homepages.feis.herts.ac.uk/~msc_fl/fl-node59.html
And the mention of templates rekindles the age old debate, can java ever be as fast as c? He he.
:-|
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Another good point, jwenting mentioned in another thread, is to tackle this problem bit by bit.
It looks as if you went onto the next stage of designing the GUI without even making sure your stack worked correctly?
I was doing something similiar just recently... Here is my code below. I've kept it short and sweet for clarity.
// Stack.java: stack implementation
public class Stack {
private int maxStack;
private int emptyStack;
private int top;
private char[] items;
public Stack(int size) {
maxStack= size;
emptyStack = -1;
top = emptyStack;
items = new char[maxStack];
}
public void push(char c) {
items[++top] = c;
}
public char pop() {
return items[top--];
}
public boolean full() {
return top + 1 == maxStack;
}
public boolean empty() {
return top == emptyStack;
}
}
//Stackmain.java
//@ Criterion for palindromes as pointed out by jwenting:
//@ The word should be exactly the same
//@ when spelt backwards
public class Stackmain {
public static void main(String[] args)
{
Stack s = new Stack(100);
// create a new stack of 100 chars
//test case alter here
String test = "eye";
//@ convert string to char array
char[] thwee = test.toCharArray();
for(int i=0; i<thwee.length; i++)
{
//@ push chars onto the stack
//@ note when we pop chars systematically
//@ from the stack it is the
//@ same as printing the
//@ original string backwards
s.push(thwee[i]);
}
int count=0;
for(int i=0; i<thwee.length; i++)
{
char temp = s.pop();
if(thwee[i]==temp)
{
// @ increment count if chars match
count++;
}
}
if(count==thwee.length)
{
System.out.println("PALINDROME");
}
else
{
System.out.println("NOT PALINDROME");
}
//System.out.println();
// while (!s.empty())
}
}
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
This is more of a question,since i don't really no myself. But it looks as if you are using syntax from c++. The < > symbols would indicate use of templates.
Since java does not support the use of templates this would be illegal?
:-|
Actually, it's called generics and it's been supported in Java for a year or so in classfile version 49.0 (compiler version 1.5, runtime version 5.0).
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Actually, it's called generics and it's been supported in Java for a year or so in classfile version 49.0 (compiler version 1.5, runtime version 5.0).
Do u have a link? Does that mean the is allowed in java? Sorrie, I like to learn all that I can.
:sad:
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Does that mean the is allowed in java?
Yes, it's called generics! I thought JW just told you that :confused:
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
check the 1.5 javadoc, especially for the Collections API. It's full of it ;)
The new version of the JLS also mentions it (if it's out by now), so does any recent Java book worth the paper it's printed on.
Then there's a load of articles all around the net.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
check the 1.5 javadoc, especially for the Collections API. It's full of it ;)
The new version of the JLS also mentions it (if it's out by now), so does any recent Java book worth the paper it's printed on.
Then there's a load of articles all around the net.
Sweet, I'm reading this up now. Ha I totally missed it wen I was doing my research on the web, probably because it's fairly recent. :eek:
Tell me does it afford the same similarities as templates do in c++?
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
yes and no. It's similar in ways, different in other ways.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337