Your code contains quite a number of syntax errors, such as unclosed strings, braces and typed arguments. Then you also keep refering to this.empty() which doesn't exist. So instead of working 1 by 1 for hours with you, heres a cleaned up version of your code, which works fine. NOTE: no logic was changed, only syntax.
import java.util.NoSuchElementException;
//import java.util.Stack;
public class LinkedStack<T> {
public static void main(String[] args){
LinkedStack<String> somestack=new LinkedStack<String>();
somestack.push("Decide");
somestack.push("Heart");
somestack.push("Fears");
somestack.push("Strength");
somestack.push("Potluck");
System.out.println("Stack is: \n"+somestack);
System.out.println("Stack is reversed: "+somestack.reversed());
}
@SuppressWarnings("hiding")
public class Node<T> {
private T info;
private Node<T> next;
public Node(T info, Node<T> next) {
this.info = info;
this.next = next;
}// Node constructor
public void setInfo(T info) {
this.info = info;
}
public T getInfo() {
return info;
}
public void setNext(Node<T> newNext) {
this.next = next;
}
public Node<T> getNext() {
return next;
}
}// end of node
private Node<T> top = null;// whenever newFS created top=null
public void push(T element) {// this push
top = new Node<T>(element, top);
}
public void push(LinkedStack<T> stack) {
// int SIZE = stack.size();
while (!(stack.isEmpty(this))) {
this.push(stack.pop());
}
}
public T peek() {
if (top == null) {
throw new NoSuchElementException();
} else
return top.getInfo();
}
public T pop() {
T element = peek();
top = top.next;
return element;
}
public boolean isEmpty(LinkedStack<T> s) {
return (top == null);
}
int count = 0;
public int size() {
count++;
return count;
}
public LinkedStack<T> reversed() {
LinkedStack<T> revertStack = new LinkedStack<T>();
// int LENGTH = this.size();
while (!(this.isEmpty(this)))// for(int j=0;j<LENGTH;j++)
{
revertStack.push(this.pop());
}
return revertStack;// end of method
}
// Returns a string representation of this stack
public String toString() {
String result = "";
Node<T> current = top;// set the current node to top
while (current != null) {// while link isn't null
result = result + (current.getInfo()).toString() + "\n";
current = current.getNext();
}
return result;// return result
}
}// end of LinkedStack