public SinglyLinkedListStack() { head = null; top = null; cur = null; // cur도 null로 해주는게 좋은건가? }
public SinglyNode Pop() { if (head == null) { Console.WriteLine("머리가 텅 빔"); return(null); } else { if (head == top) { SinglyNode tmp = new SinglyNode(top.val); head = null; top = null; return(tmp); } else // (head != top) { SinglyNode tmp = top; SinglyNode i; for (i = head; i.next != top; i = i.next) { ; } top = i; return(tmp); } } }
public void Push(int val) { if (head == null) { SinglyNode tmp = new SinglyNode(val); head = tmp; top = tmp; } else // head != null { if (head == top) { SinglyNode tmp = new SinglyNode(val); if (top.val < val) { top.next = tmp; top = tmp; } else { tmp.next = top; head = tmp; } } else // head != top { SinglyNode tmp = new SinglyNode(val); if (head.val >= val) { tmp.next = head; head = tmp; } else if (top.val <= val) { top.next = tmp; top = tmp; } else if (head.val < val && top.val > val) { SinglyNode i; for (i = head.next, cur = head; i != top.next; i = i.next) { if (i.val >= val) { tmp.next = i; cur.next = tmp; break; } cur = i; } } } } }
public void Push(int val) { // 아직 아무값도 없으면 head, top이 그 노드를 가리키게 함 if (head == null) { SinglyNode tmp = new SinglyNode(val); head = tmp; top = tmp; } // head에 값이 있다면 새 노드를 top.next에 연결하고 top이 새 노드를 가리킴 else if (head != null) { SinglyNode tmp = new SinglyNode(val); top.next = tmp; top = tmp; } }
public SinglyNode Pop() { // i) 아무것도 없으면 안뺌 // ii) 하나만 있으면 걔를 빼고 head, top을 null로 // iii) 둘 이상 있으면 top은 cur이 가리키는걸 가리키게 하고 // cur.next가 top일때까지 찾아 그곳에 cur를 위치시킨 다음 // top.next를 return해줌 if (head == null) { Console.WriteLine("머리가 텅 빔"); return(null); } else { if (head == top) { SinglyNode tmp = new SinglyNode(top.val); head = null; top = null; return(tmp); } else // (head != top) { SinglyNode tmp = top; for (SinglyNode i = head; i != top; i = i.next) { if (i.next == top) { cur = i; } } top = cur; return(tmp); } } }
public InsertionSortLinkedList() { head = null; top = null; cur = null; }
public SinglyNode(int _val) { val = _val; next = null; }