#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
int data;
struct Node* next;
}node;
void disp(node* move) {
while (move != NULL) {
printf("%d", move->data); //현재 move 위치
move = move->next; // 다음 노드로 한칸씩 이동
}
printf("\n");
}
void input(node** head, int data) {
node* newnode = (node*)malloc(sizeof(node));
newnode->data = data;
newnode->next = (*head)->next;
(*head)->next = newnode;
}
void search_node(node* move) {
int data;
printf("찾으시는 데이터 입력 : ");
scanf("%d", &data);
while (move != NULL) {
if (move->next->data == data) {
//찾는 데이터가 노드에 있을 경우
printf("%d \n", move->data);
printf("찾으시는 데이터가 있습니다.");
break;
}
move = move->next;
//없을 경우, 그냥 종료
}
}
void main() {
//input 함수에 들어갈 때 마다
//newnode 생성 후, 보내준 인자값
//newnode->data에 대입
node* head = (node*)malloc(sizeof(node));
head->next = NULL;
input(&head,10);
input(&head,20);
input(&head,30);
disp(head->next);
system("pause");
}
댓글 없음:
댓글 쓰기