Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- }
- System.out.print(" " + (char)tmp.getInf());
- public void showList() {
- Node tmp=first;
- while (tmp!=null) {
- System.out.print(" "+ (char)tmp.getInf()); //здесь преобразование кода в символ
- tmp=tmp.getNext();
- }
- System.out.println();
- }
- //Node
- private Object inf;
- Node(Object inf){
- this.inf = inf;
- next = null;
- }
- public void setInf(Object inf){
- this.inf = inf;
- }
- public Object getInf(){
- return inf;
- }
- //List
- public void addFirst(Object inf){
- Node newnode = new Node(inf);
- addFirstNode(newnode);
- }
- public void addLast(Object inf){
- Node newnode = new Node(inf);
- addLastNode(newnode);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement