Example #1
0
        private node remove(ref linknode thenode)
        {
            if (thenode == null)
            {
                return(null);
            }
            node     retval     = thenode.data;
            linknode beforenode = thenode.prev;
            linknode afternode  = thenode.next;

            thenode = null;
            //리스트의 머리쪽에서 remove되었는지 꼬리쪽에서 remove되었는지 판별
            //이를 이용해 firstelem과 lastelem을 올바르게 조정한다
            if (beforenode == null)
            {
                firstelem = afternode;
            }
            if (afternode == null)
            {
                lastelem = beforenode;
            }

            if (beforenode != null)
            {
                beforenode.next = afternode;
            }
            if (afternode != null)
            {
                afternode.prev = beforenode;
            }
            return(retval);
        }
Example #2
0
        //느린 정렬이지만 구현하기 쉬우면서도 안정적으로 작동하기에 failsafe 용도로 남겨둔다.
        private void bubble_sort_by_fval()
        {
            linknode it;
            linknode bubblelast = lastelem;

            while (bubblelast != firstelem)
            {
                it = firstelem;
                while (it.data != null)
                {
                    if (it.data.f > it.next.data.f)
                    {
                        node temp = it.data;
                        it.data      = it.next.data;
                        it.next.data = temp;
                    }
                    if (it.next == bubblelast)
                    {
                        break;
                    }
                    it = it.next;
                }
                bubblelast = it;
            }
        }
Example #3
0
        private void quick_sort_by_fval(linknode left, linknode right)
        {
            linknode left_it = left, right_it = right;
            node     pivot = left_it.data;

            while (left_it != right_it)
            {
                while (left_it != right_it && right_it.data.f >= pivot.f)
                {
                    right_it = right_it.prev;
                }
                if (left_it != right_it)
                {
                    left_it.data = right_it.data;
                }
                while (left_it != right_it && left_it.data.f <= pivot.f)
                {
                    left_it = left_it.next;
                }
                if (left_it != right_it)
                {
                    right_it.data = left_it.data;
                }
            }
            //left_it(==right_it)는 중앙(pivot)을 가리키고 있다.
            left_it.data = pivot;
            if (left_it != left)
            {
                quick_sort_by_fval(left, left_it.prev);
            }
            if (left_it != right)
            {
                quick_sort_by_fval(left_it.next, right);
            }
        }
Example #4
0
 //좌표값이 같으면 같은 데이터이다.
 public linknode search(node data)
 {
     for (linknode it = firstelem; it != null; it = it.next)
     {
         if (it.data.pos[0] == data.pos[0] && it.data.pos[1] == data.pos[1])
         {
             return(it);
         }
     }
     return(null);
 }
Example #5
0
        //lastelem이나 firstelem이 알맞은 값으로 설정되었는지 자동으로 확인/교정해준다.
        //다만 매개변수들이 올바른 값인지는 검사하지 않기 때문에
        //( - beforedata와 afterdata는 붙어있는가? )
        //( - 정말로 리스트의 beforedata와 afterdata 사이인가? )
        //( - data는 유효한 값인가? )
        //public으로 풀기엔 무리가 있는 것 같다.
        private void insert(linknode beforedata, node data, linknode afterdata)
        {
            linknode temp = new linknode(data, beforedata, afterdata);

            //리스트의 머리쪽에서 insert되었는지 꼬리쪽에서 insert되었는지 판별
            //이를 이용해 firstelem과 lastelem을 올바르게 조정한다
            if (beforedata == null)
            {
                firstelem = temp;
            }
            if (afterdata == null)
            {
                lastelem = temp;
            }

            if (beforedata != null)
            {
                beforedata.next = temp;
            }
            if (afterdata != null)
            {
                afterdata.prev = temp;
            }
        }
Example #6
0
 public linknode(node data, linknode prev, linknode next)
 {
     this.data = data; this.prev = prev; this.next = next;
 }