728x90
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
int node_find(struct node *head, int key);
void list_print(struct node *);
void main(){
struct node a, b, c;
struct node *head;
int find, key;
head=&a;
a.data = 10;
b.data = 20;
c.data = 30;
a.next= &b;
b.next = &c;
c.next = NULL;
list_print(head);
while(key!=-1)
{
printf("\n>>데이터 찾기\n찾고자 하는 데이터 : ");
scanf("%d",&key);
find = node_find(head,key);
if(find)
printf("찾기 성공\n");
else
printf("못찾음ㅋㅁ\n");
}
}
void list_print(struct node *head){
for(; head; head=head->next)
printf("%d\n", head->data);
}
int node_find(struct node *head, int key)
{
for(; head; head=head->next)
{
if(head->data==key)
{
printf("\n%d\n", head->data);
return head->data;
}
}
return 0;
}
'it > programming' 카테고리의 다른 글
| 티스토리에서 Javascript로 레이어 팝업 띄우기 (2) | 2013.01.03 |
|---|---|
| [c++] 구조체 포인터 node 관리 - insert (0) | 2012.11.26 |
| [c++] 구조체 포인터 node 관리 - add (0) | 2012.11.26 |