We set the task to write a program in which, having a string, you need to form a queue with paired characters and a stack with every fifth character. I am not very strong in this, but I did such a program, but it doesn’t produce what I need (everything works out with an array of numbers). How to remake a line? Help, I will be very grateful.
public class Node { private int inf; private Node next; Node() { inf=0; next=null; } Node(int i) { inf=i; next=null; } public void setInf(int i) { inf=i; } public void setNext(Node n) { next=n; } public int getInf() { return inf; } public Node getNext() { return next; } } public class List { private Node first; List() { first=null; } public void addFirstNode(Node n) { n.setNext(first); first=n; } public void addLastNode(Node n) { if (first==null) first=n; else { Node tmp=first; while (tmp.getNext()!=null) { tmp=tmp.getNext(); } tmp.setNext(n); } } public void addFirst(int a) { Node newnode = new Node(a); addFirstNode(newnode); } public void addLast(int a) { Node newnode = new Node(a); addLastNode(newnode); } public void showList() { Node tmp=first; while (tmp!=null) { System.out.print(" "+tmp.getInf()); tmp=tmp.getNext(); } System.out.println(); } } package dom; //основная программа public class Dom { public static void main(String[] args) { List queue = new List(); List stack = new List(); String s = "125478965321547896521547889633215478965487512546985478521"; int l = s.length(); for (int i=0; i<l; i++) { if (i%2==0) { char k=s.charAt(i); queue.addLast(k); } if (i%5==0) { char k=s.charAt(i); stack.addFirst(k); } } queue.showList(); stack.showList(); } }