-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_list.c
More file actions
100 lines (65 loc) · 1.3 KB
/
linked_list.c
File metadata and controls
100 lines (65 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>
#include <stdlib.h>
typedef struct nodo{
int data;
struct nodo *sig;
}Node;
Node *raiz=NULL,*fin=NULL;
void insertNode(int num,Node * node ){
if(raiz==NULL){
raiz=node;
fin=node;
node->data=num;
node->sig=NULL;
}else{
fin->sig=node;
node->data=num;
node->sig=NULL;
fin=node;
}
}
void print_list(Node *raiz){
Node *current=raiz ;
while(current!=NULL){
printf("%d\n",current->data);
current=current->sig;
}
}
void findData(Node *raiz,int data){
Node *current =raiz;
int count=0;
while(current!=NULL){
if(current->data==data){
printf("data found in node %d\n",count+1);
}
current=current->sig;
count++;
}
}
int main(){
int optChoosed,num;
do {
printf("1.-insertar un dato\n");
printf("2.-recorrer la lista\n");
printf("3.-buscar dato\n");
printf("6.-salir\n");
scanf("%d\n",&optChoosed);
switch (optChoosed){
case 1:
printf("Dame el dato a insertar");
scanf("%d",&num);
Node *node=(Node *)malloc (sizeof(Node ));
insertNode(num,node);
break;
case 2:
print_list(raiz);
break;
case 3:
printf("dame el numero a buscar ");
scanf("%d",&num);
findData(raiz,num);
break;
}
}while(optChoosed!=6);
return 0;
}