When i print elements from my stack it will have a large amount of blank spaces or whitespace between each element.
I want to be able to print them out much closer together if possible.
It will retain the elements in the stack in their position and just negate all letters besides the one i am currently grabbing.
import java.io.*;
public class File
{
public static void main(String[] args) {
try {
BufferedReader in = new BufferedReader( new
FileReader("input.txt"));
String str;
while( (str = in.readLine()) != null){
System.out.println("I just read: "+ str);
StackOfStrings[] ss = new StackOfStrings[35];
for(int i=0; i <= 9; i++){
ss[i] = new StackOfStrings();
}
if(str.charAt(4) == 'm') {
ss[0].push("m");
}
}
in.close();
} catch(IOException e) {
System.out.println(e.getMessage());
}
}
}
This is the other half without the interface
public class StackOfStrings implements StackInterface {
private Node first; //top
private int n;
public StackOfStrings(){
first = null;
n=0;
}
public boolean isEmpty() {
return first == null;
}
public int size() {
return n;
}
public void push(String item)
{
Node x = new Node();
x.item = item;
x.next = first;
first = x;
}
public String pop() {
String val = first.item;
first = first.next;
n--;
return val;
}
private class Node {
String item;
Node next;
}
public String toString()
{
String s="";
Node t = first;
while(t != null) {
s += t.item + " ";
t= t.next;
}
return s;
}
}