Dev - C++ - listas c++

 
Vista:

listas c++

Publicado por andres (1 intervención) el 22/09/2008 22:45:22
hola amigos....me urge resolver este codigo...es que le he intentado por todos lados y no me anda ......porfavorayuuuuuuuuuuuuuuuuuuuuuuudenme........

este es el codigo......
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# include <iostream.h>
# include <conio.h>
#include <stdio.h>
typedef struct NODO NODO;
struct NODO
 
{
 
int info;
NODO *sig;
};
 
//******************************************
 
class LISTA
 {
 
NODO*cab;
 
public:
LISTA()
	{
   cab=NULL;
   }
int ins_lista(int n);
int retira_lista(int n);
void listar_lista();
void insertar(NODO*,NODO*,int);
~LISTA();
 
}
//******************************************
 
{
void LISTA::insertar(NODO*p,NODO*q,int n)
 
NODO*nuevo;
nuevo=new NODO;
nuevo->info=n;
nuevo->sig=q;
if(p!=NULL)
p->sig=nuevo;
else cab=nuevo;
}
 
//*******************************************
int LISTA::ins_lista(int n)
{
NODO*p,*q;
p=NULL;
q=cab;
int encontro=0;
while(q!=NULL&&! encontro)
if(n>q->info)
	{
	p=q;
	q=q->sig;
	}
else encontro=1;
if(encontro)
if(n==q->info)
return(-1);//repetido
else insertar(p,q,n);
return 0;
}
 
//*******************************************
int LISTA::retira_lista(int n)
{
NODO*p,*q ;
p=NULL;
q=cab;
int encontro=0;
while(q!=NULL&&!encontro)
if(n>q->info)
	{
	p=q;
	q=q->sig;
	}
 
	else encontro=1;
	if(encontro==1&&n==q->info)
	{
	if(p==NULL)
	cab=q->sig;
	else p->sig=q->sig;
	delete q;
	return 0;
	}
 
	return -1;
}
//*******************************************
void LISTA::listar_lista()
{
NODO *p;
while(p!=NULL)
	{
	cout<<p->info<<endl;
	p=p->sig;
	}
}
//*******************************************
LISTA::~LISTA()
{
NODO*p;
if(cab==NULL)
 
else
	{
	p=cab;
	while(cab!=NULL)
   	{
		cab=cab->sig;
		delete p;
		cout<<"destruido nodo..."<<endl;
		p=cab;
		}
	}
}
 
//********************************************
main()
{
LISTA lista1;
int i;
 
lista1.f(int i);
 
cout<<"de numero(para fin de 999)..."<<endl;
cin>>i;
while(i!=999)
	{
   if(lista1.ins_lista(i)==-1)
	cout<<"repetido..."<<endl;
	cout<<"de numero (para fin de 999)...."<<endl;
  	cin>>i;
	}
lista1.listar_lista();
cout<<"de numero a retirar(para fin de 999)..."<<endl;
cin>>i;
while (!=999)
	{
	if (lista1.retira_lista(i)==-1)
	cout<<"No existe"<<endl;
	cout<<   "de numero a retirar(para fin de 999)..."<<endl;
	cin>>i;
	}
lista1.listar_lista();
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder