Skip to content

Edge에서 공유됨 #3

@ghost

Description

아래는 C 언어로 노드 추가, 삭제 및 찾기 기능이 있는 링크된 목록 구조에 대한 코드입니다. 이 코드는 단일 연결 리스트(single linked list)를 구현합니다. 단일 연결 리스트는 각 노드가 데이터와 링크를 가지며, 각 노드가 링크를 이용해서 연결되는 방식으로 데이터를 저장하는 구조입니다. 이 코드는 노드 추가, 삭제, 찾기 기능을 구현합니다.

#include <stdio.h>
#include <stdlib.h>

struct node {
    int data;
    struct node* next;
};

struct node* head = NULL;

void insert(int new_data) {
    struct node* new_node = (struct node*)malloc(sizeof(struct node));
    new_node->data = new_data;
    new_node->next = head;
    head = new_node;
}

void delete(int key) {
    struct node* temp = head, * prev;

    if (temp != NULL && temp->data == key) {
        head = temp->next;
        free(temp);
        return;
    }

    while (temp != NULL && temp->data != key) {
        prev = temp;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions