Skip to content

Commit a6415f1

Browse files
authored
lab_4
Mi solución al laboratorio 4
1 parent 34f54bd commit a6415f1

File tree

1 file changed

+203
-0
lines changed

1 file changed

+203
-0
lines changed

lab_4.cpp

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
practica_4.txt
2+
Anteriormente este año
3+
6 ene
4+
F
5+
Has modificado los permisos de un elemento
6+
Texto
7+
practica_4.txt
8+
9+
Puede editar
10+
Freddy Campos
11+
12+
kenly deffitt
13+
Hace mucho tiempo
14+
26 feb 2019
15+
F
16+
Has modificado los permisos de un elemento
17+
Texto
18+
practica_4.txt
19+
20+
Puede ver
21+
kenly deffitt
22+
26 feb 2019
23+
F
24+
Has compartido un elemento
25+
Texto
26+
practica_4.txt
27+
28+
Puede editar
29+
kenly deffitt
30+
5 sept 2016
31+
F
32+
Has subido un elemento
33+
Texto
34+
practica_4.txt
35+
#include <iostream>
36+
#include <fstream>
37+
#include <iomanip>
38+
#include <stdlib.h>
39+
#include <string.h>
40+
//declaracion------------------------------------
41+
struct _dato{
42+
int n;
43+
char palabra[25];
44+
};
45+
typedef _dato dato;
46+
struct nodo{
47+
dato info;
48+
nodo *ant, *sig;
49+
};
50+
typedef nodo *ptnodo;
51+
ptnodo lista_d = NULL;
52+
//funiones----------------------------------------
53+
void INSERTAR_FIN(ptnodo &Ld, dato X);
54+
ptnodo ULTIMO(ptnodo &Ld);
55+
void MOSTRAR_LISTA (ptnodo &Lista);
56+
void BORRAR_LISTA(ptnodo &Ld);
57+
void buscar_pal(ptnodo Ld, char pal[]);
58+
using namespace std;
59+
int main(){
60+
ifstream A1;
61+
char aux[25], let, pal[25];
62+
int i, flag = 0, cont = 0,opc = 0, ban = 0;
63+
dato regis;
64+
while(opc != 6){
65+
cout << "Menu de opciones\n";
66+
cout << "1.- Cargar un archivo de texto\n";
67+
cout << "2.- Mostrar la lista de palabras\n";
68+
cout << "3.- Agregar datos\n";
69+
cout << "4.- Buscar palabra\n";
70+
cout << "5.- Opcion extra\n";
71+
cout << "6.- Salir\n";
72+
cin >> opc;
73+
system("cls");
74+
switch(opc){
75+
case 1:
76+
cont = 0;
77+
if(lista_d != NULL)
78+
BORRAR_LISTA(lista_d);
79+
A1.open("texto.txt");
80+
if (!A1){
81+
cout << "Problemas con archivo\n";
82+
break;
83+
}
84+
A1.get(let);
85+
while(! A1.eof()){
86+
i = 0;
87+
flag = 0;
88+
while(isalpha(let)){
89+
aux[i] = let;
90+
A1.get(let);
91+
i ++;
92+
flag = 1;
93+
}
94+
if(flag == 1){
95+
aux [i] = '\0';
96+
cont ++;
97+
regis.n = cont; strcpy(regis.palabra,aux);
98+
INSERTAR_FIN(lista_d, regis);
99+
}
100+
A1.get(let);
101+
}
102+
ban = 1;
103+
A1.close();
104+
break;
105+
case 2:
106+
if (ban){
107+
MOSTRAR_LISTA (lista_d);
108+
}else
109+
cout << "Se deben cargar los datos primero\n";
110+
break;
111+
case 3:
112+
break;
113+
case 4:
114+
cout << "ingrese la palabra a buscar\n";
115+
cin.ignore(1);
116+
cin.getline(pal, 25);
117+
buscar_pal(lista_d, pal);
118+
break;
119+
case 5:
120+
break;
121+
case 6:
122+
if(lista_d != NULL)
123+
BORRAR_LISTA(lista_d);
124+
break;
125+
default:
126+
cout << "Ingrese una opcion valida\n";
127+
break;
128+
}
129+
}
130+
return 0;
131+
}
132+
void INSERTAR_FIN(ptnodo &Ld, dato X){
133+
ptnodo NUEVO, U;
134+
NUEVO = new(nodo);
135+
NUEVO -> info = X;
136+
NUEVO -> sig = NULL; NUEVO -> ant = NULL;
137+
if(Ld == NULL) Ld = NUEVO;
138+
else
139+
{ U = ULTIMO(Ld);
140+
U -> sig = NUEVO;
141+
NUEVO -> ant = U;
142+
}
143+
}
144+
ptnodo ULTIMO(ptnodo &Ld){
145+
ptnodo A = Ld;
146+
if(A != NULL){
147+
while (A -> sig != NULL)
148+
A = A -> sig;
149+
return A;
150+
}else {
151+
cout << "Lista vacia\n";
152+
return NULL; }
153+
}
154+
void MOSTRAR_LISTA (ptnodo &Lista){
155+
ptnodo A = Lista;
156+
if (A != NULL){
157+
while(A != NULL){
158+
cout << setw(3) << A -> info.n << setw(20) << A -> info.palabra << endl;
159+
A = A -> sig;
160+
}
161+
}
162+
else cout << "Lista vacia\n";
163+
}
164+
void BORRAR_LISTA(ptnodo &Ld){
165+
ptnodo P = Ld;
166+
if(Ld != NULL){
167+
if(P == Ld && P -> sig == NULL)
168+
Ld = NULL;
169+
else{
170+
Ld = Ld -> sig;
171+
Ld -> ant = NULL;
172+
}
173+
delete(P);
174+
BORRAR_LISTA(Ld);
175+
}
176+
}
177+
void buscar_pal(ptnodo Ld, char pal[]){
178+
ptnodo A = Ld, P[15];
179+
int b = 0, a = 4, i = 0;
180+
for(i = 0; i < b; i++)
181+
P[i] = NULL;
182+
if(A != NULL){
183+
while(A != NULL){
184+
a = strcmp(pal, A -> info.palabra);
185+
if(!a){
186+
b ++;
187+
P[i] = A;
188+
i++;
189+
}
190+
A = A -> sig;
191+
}
192+
}else{
193+
cout << "La lista esta vacia\n";
194+
}
195+
if (b){
196+
cout << "Palabra encontrada\n";
197+
for(i = 0; i < b; i++){
198+
cout << setw(3) << P[i] -> info.n << setw(20) << P[i] -> info.palabra << endl;
199+
P[i] = NULL;
200+
}
201+
}else
202+
cout << "No hay coincidencia\n";
203+
}

0 commit comments

Comments
 (0)