Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. public class SnocList {
  2. private char c;
  3. private SnocList l;
  4.  
  5. public SnocList(){
  6. }
  7. public SnocList (char x, SnocList y) {
  8. this.c = x;
  9. this.l = y;
  10. }
  11. public char getC(){
  12. return this.c;
  13. }
  14. public SnocList getL(){
  15. return this.l;
  16. }
  17. public void setNext(SnocList input){
  18. this.l = input;
  19. }
  20.  
  21. public boolean isEmpty() {
  22. if (this.c == 0) return true;
  23. return false;
  24. }
  25. }
  26.  
  27. public class SnocQueue {
  28. private SnocList list;
  29.  
  30. public SnocQueue(){
  31. this.list = new SnocList();
  32. }
  33.  
  34. public void enqueue(char c){
  35. //I don't know what to put here
  36. }
  37. }
  38.  
  39. public class Item {
  40. private int value;
  41. private Item next;
  42.  
  43. public Item(int val) {
  44. this.value = val;
  45. }
  46.  
  47. public void setNext(Item item) {
  48. this.next = item;
  49. }
  50. }
  51.  
  52. public class SomeQueue {
  53. private Item head;
  54. private Item tail;
  55. private int size;//size is used to verify if it has Items and avoid null references
  56.  
  57. public SomeQueue(){
  58. this.size = 0;
  59. }
  60. public void enqueue(Item item) {
  61. if (this.size > 0) {
  62. this.tail.setNext(item);
  63. this.tail = item;
  64. } else { //this is when the size is 0, it means is empty
  65. this.head = item;
  66. this.tail = item;
  67. }
  68. this.size++;
  69. }
  70. }
  71.  
  72. public class SnocQueue {
  73. SnocList head;
  74.  
  75. public void enqueue(char ch) {
  76. if(head == null) {
  77. head = new SnocList(ch, null);
  78. return;
  79. } else {
  80. SnocList curr = head;
  81. while (curr.l != null) {
  82. curr = curr.l;
  83. }
  84. curr.l = new SnocList(ch, curr.l);
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement