Guest User

Untitled

a guest
Mar 22nd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. Stack <TagNode> stk = new Stack <TagNode>();
  2. TagNode temp;
  3. if(!sc.hasNext()){
  4. return;
  5. }
  6. while (sc.hasNext()){
  7. String next = sc.nextLine();
  8. int length = next.length();
  9.  
  10. if(!next.contains("<")) { // for words in sentences and such
  11. temp=new TagNode (next, null, null);
  12. if(stk.peek().firstChild!=null) {
  13. stk.peek().sibling=temp;
  14. }else {
  15. stk.peek().firstChild=temp;
  16. }
  17. }
  18.  
  19. else if(next.contains("/")) {
  20. temp = stk.pop();
  21. if(!stk.isEmpty()) {
  22. if(stk.peek().firstChild!=null) {
  23. stk.peek().sibling=temp;
  24. }else {
  25. stk.peek().firstChild=temp;
  26. }
  27. }else {root=temp;}
  28. }
  29.  
  30. else if(next.contains("<")) { //opening tag
  31. stk.push(new TagNode (next.substring(1, length-1), null, null));
  32. }
  33. }
Add Comment
Please, Sign In to add comment