Docsity

pilas y colas en dev c++, Exámenes de Algoritmos y Programación

Toggle sidebar
bg1
Lista simple
#include <iostream>
using namespace std;
class LISTA{
int info;
LISTA *sgte;
public:
void menu(){
cout<< "\nMENU DE OPCIONES\n";
cout<< "----------------\n" ;
cout<<"<1> Ingresar Lista\n";
cout<<"<2> Mostrar Lista\n";
cout<<"<3> Salir \n";
}
void ingresaLista (LISTA *&raiz, int x){
LISTA *q;
LISTA *n =new LISTA;
n->info=x;
if(raiz==NULL)
raiz=n;
else{
q=raiz;
while (q->sgte!= NULL)
q=q->sgte;
q->sgte=n;
}
n->sgte=NULL;
}
void mostrarLista (LISTA *raiz){
LISTA *ptr;
ptr= raiz;
while( ptr!= NULL) {
cout<<" "<<ptr->info;
ptr=ptr->sgte;
}
cout<<endl;
}
};
int main(int argc, char** argv) {
char opcion;
int x;
LISTA lista;
LISTA *raiz=NULL;
do{
lista.menu();
cout<<"\ningrese opcion : ";
opcion=cin.get();
switch(opcion){
case '1':
cout<<"\n ingrese un numero: ";cin>>x;
lista.ingresaLista(raiz,x);
break;
pf2

Vista previa parcial del texto

¡Descarga pilas y colas en dev c++ y más Exámenes en PDF de Algoritmos y Programación solo en Docsity!

Lista simple

#include using namespace std; class LISTA{ int info; LISTA *sgte; public: void menu(){ cout<< "\nMENU DE OPCIONES\n"; cout<< "----------------\n" ; cout<<"<1> Ingresar Lista\n"; cout<<"<2> Mostrar Lista\n"; cout<<"<3> Salir \n"; } void ingresaLista (LISTA *&raiz, int x){ LISTA *q; LISTA *n =new LISTA; n->info=x; if(raiz==NULL) raiz=n; else{ q=raiz; while (q->sgte!= NULL) q=q->sgte; q->sgte=n; } n->sgte=NULL; } void mostrarLista (LISTA *raiz){ LISTA *ptr; ptr= raiz; while( ptr!= NULL) { cout<<" "<<ptr->info; ptr=ptr->sgte; } cout<<endl; } };

int main(int argc, char** argv) { char opcion; int x; LISTA lista; LISTA *raiz=NULL; do{ lista.menu(); cout<<"\ningrese opcion : "; opcion=cin.get(); switch(opcion){ case '1': cout<<"\n ingrese un numero: ";cin>>x; lista.ingresaLista(raiz,x); break;

case '2': lista.mostrarLista(raiz); break; } cin.ignore(); } while( opcion !='3'); return 0; }