Skip to content

Commit

Permalink
Sturct Node Insert
Browse files Browse the repository at this point in the history
단순 연결 리스트 삽입
  • Loading branch information
hyejun0608 committed Sep 10, 2020
1 parent d2abfe7 commit 497085b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions struct Node Insert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include<stdio.h>
#include<windows.h>

typedef struct NODE* NodePointer;
typedef struct NODE {
int data;
NodePointer link;
}NODE;
NodePointer head = NULL;

int Search(NodePointer ptr, int value) {
int i;
for (i = 1; ptr->data != value; ptr->link) i++;
return i;
}

void Insert(NodePointer pre, int value) {
NodePointer temp = (NodePointer)malloc(sizeof(NODE));
if (!head) { // 리스트가 공백인 상태
temp->data = value;
temp->link = NULL;
head = temp;
}
else { // 리스트가 공백이 아닌 상태
temp->data = value;
temp->link = pre->link;
pre->link = temp;
}
}

int main() {
Insert(head, 1);
printf("%d", head->data);
}

0 comments on commit 497085b

Please sign in to comment.