๐Ÿ““ STUDY/FASTCAMPUS

ํŒจ์ŠคํŠธ์บ ํผ์Šค ์ฑŒ๋ฆฐ์ง€ 21์ผ์ฐจ

JuneBee 2021. 11. 21. 19:46
728x90
๋ฐ˜์‘ํ˜•

๊ฐ•์˜ ๋‚ ์งœ : 2021/11/21
์‹œ์ฒญ ๊ฐ•์˜ : ์€๊ทผํžˆ ์–ด๋ ค์šด ์ž๋ฃŒ๊ตฌ์กฐ : ๋งํฌ๋“œ ๋ฆฌ์ŠคํŠธ(4)

๋“œ๋””์–ด ๋งํฌ๋“œ ๋ฆฌ์ŠคํŠธ ๊ฐ•์˜๊ฐ€ ๋๋‚ฌ๋‹ค.

๋‚˜๋Š” ์–ด์ œ ๋งˆ์ € ๊ณต๋ถ€ํ•˜๋‹ค ์˜ฌ๋ฆฐ ์›ํ˜• ๋งํฌ๋“œ ๋ฆฌ์ŠคํŠธ ๊ตฌํ˜„์„ ๋งˆ์ € ์˜ฌ๋ฆฌ๋„๋ก ํ•˜๊ฒ ๋‹ค.

์›ํ˜• ๋งํฌ๋“œ ๋ฆฌ์ŠคํŠธ(2)

๋งจ ๋’ค์— ์ƒˆ๋กœ์šด ๋…ธ๋“œ ์ถ”๊ฐ€

static Node addEnd(Node last, int data)
{
    if (last == null)
        return addToEmpty(last, data);
     
    Node temp = new Node();
 
    temp.data = data;
    temp.next = last.next;
    last.next = temp;
    last = temp;
 
    return last;
}

ํŠน์ • ๋…ธ๋“œ ๋’ค์— ์ถ”๊ฐ€

static Node addAfter(Node last, int data, int item)
{
    if (last == null)
        return null;
 
    Node temp, p;
    p = last.next;
    do
    {
        if (p.data == item)
        {
            temp = new Node();
            temp.data = data;
            temp.next = p.next;
            p.next = temp;
 
            if (p == last)
                last = temp;
            return last;
        }
        p = p.next;
    } while(p != last.next);
 
    System.out.println(item + " not present in the list.");
    return last;
 
}

๋…ธ๋“œ ์‚ญ์ œ

//์ฃผ์–ด์ง„ ํ‚ค ๋…ธ๋“œ ์‚ญ์ œ
static Node deleteNode(Node head, int key)
    {
        if (head == null) //๋ฆฌ์ŠคํŠธ๊ฐ€ ๋น„์–ด์žˆ๋Š” ๊ฒฝ์šฐ
            return null;
 
        Node curr = head, prev = new Node();
        while (curr.data != key) {
            if (curr.next == head) { //๋ชป์ฐพ์€ ๊ฒฝ์šฐ
                System.out.printf("Key does not exist int this list");
                break;
            }
 
            prev = curr;
            curr = curr.next;
        }
    }

Code Reference : Geeks for Geeks


ํŒจ์ŠคํŠธ์บ ํผ์Šค ํ™˜๊ธ‰ ์ฑŒ๋ฆฐ์ง€ ๋ฐ”๋กœ๊ฐ€๊ธฐ๐Ÿ‘‰ https://bit.ly/3FVdhDa

 

์ˆ˜๊ฐ•๋ฃŒ 100% ํ™˜๊ธ‰ ์ฑŒ๋ฆฐ์ง€ | ํŒจ์ŠคํŠธ์บ ํผ์Šค

๋”ฑ 5์ผ๊ฐ„ ์ง„ํ–‰๋˜๋Š” ํ™˜๊ธ‰์ฑŒ๋ฆฐ์ง€๋กœ ์ˆ˜๊ฐ•๋ฃŒ 100% ํ™˜๊ธ‰๋ฐ›์œผ์„ธ์š”! ๋” ๋Šฆ๊ธฐ์ „์— ์ž๊ธฐ๊ณ„๋ฐœ ๋ง‰์ฐจ ํƒ‘์Šน!

fastcampus.co.kr

๋ณธ ํฌ์ŠคํŒ…์€ ํŒจ์ŠคํŠธ์บ ํผ์Šค ํ™˜๊ธ‰ ์ฑŒ๋ฆฐ์ง€ ์ฐธ์—ฌ๋ฅผ ์œ„ํ•ด ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•