SoloCodigo
Programación General => C/C++ => Mensaje iniciado por: tany666 en Miércoles 6 de Marzo de 2002, 09:38
-
PoR FAVOR NECESITO AYUDA URGENTEMENTE,NECESITO UN PROGRAMA DE ESTRUCTURAS DINAMICAS CON UN MENU CON VENTANAS Y FUNCIONES EN C++,DONDE SE PUEDAN INTRODUCIR,ELIMINAR,MODIFICAR..DATOS,PORFAVOR ES URGENTE, MUCHISIMAS GRACIAS :(
-
PoR FAVOR NECESITO AYUDA URGENTEMENTE,NECESITO UN PROGRAMA DE ESTRUCTURAS DINAMICAS CON UN MENU CON VENTANAS Y FUNCIONES EN C++,DONDE SE PUEDAN INTRODUCIR,ELIMINAR,MODIFICAR..DATOS,PORFAVOR ES URGENTE, MUCHISIMAS GRACIAS :(
-
-
Pretendes que te haban la tarea????
y no escribas con mayusculas ;)
-
si esto te puede servir mas bien como ejemplo y mirar como funcionan las listas...este ejemplo es de listas circulares
:
# ifndef PA_h
# define PA_h
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
#define TIPO int
typedef struct nodo
{
TIPO info;
struct nodo *enlace;
struct nodo *enlace1;
}LISTA;
int menu(void);
void inserta_final(LISTA **ptr, char elemento);
void inserta_or(LISTA **ptr,LISTA **p, char elemento);
void orden(LISTA **ptr,LISTA **p);
void elim_ele_lista(LISTA **ptr);
void buscar_ele(LISTA **ptr,LISTA **p, char elemento);
void mostrar_elementos(LISTA **ptr,LISTA **p);
void inserta_final(LISTA **ptr,LISTA **p, char elemento)
{
LISTA *p1, *p2,*aux;
p1 = *ptr;
if(p1 == NULL)
{
p1 = new(LISTA);
if (p1 != NULL)
{
p1->info = elemento;
p1->enlace = p1;
p1->enlace1 = p1;
*ptr = p1;
*p = p1;
}
}
else
{ aux=p1;
while(p1->enlace != aux)
p1 = p1->enlace;
p2 = new(LISTA);
if(p2 != NULL)
{
p2->info = elemento;
p2->enlace = aux;
p1->enlace = p2;
p2->enlace1 = p1;
aux->enlace1 =p2;
*p = p2;
}
}
}
int menu(void)
{
int car;
clrscr();
printf("n opcion 1 insertar final elementos en la lista ");
printf("n opcion 2 sacar un elemento de la lista");
printf("n opcion 3 insertar ordenadamente");
printf("n opcion 4 ordenar inserci¢n");
printf("n opcion 5 buscar elemento");
printf("n opcion 6 mostrar elementos");
printf("n opcion 7 Exitn");
do{
car=getche();
}while(car<49||car>55);
return car;
}
void elim_ele_lista(LISTA **ptr,LISTA **p)
{
LISTA *aux,*aux1,*aux2;
aux=*ptr;
if(aux!=NULL){
if(aux->enlace!=aux){
*ptr=aux->enlace;
aux1=*ptr;
aux1->enlace1=aux->enlace1;
aux2=*p;
aux2->enlace=aux1;
printf("nnEl elemento eliminado es %c",aux->info);
delete(aux);
}
else
{
printf("nnEl elemento eliminado es %c",aux->info);
delete(aux);
*ptr=NULL;
*p=NULL;
}
}
else
printf("Lista vac¡a");
}
void inserta_or(LISTA **ptr,LISTA **p, char elemento)
{
LISTA *p1, *p2,*aux,*aux1;
p1 = *ptr;
if(p1 == NULL)
{
p1 = new(LISTA);
if (p1 != NULL)
{
p1->info = elemento;
p1->enlace = p1;
p1->enlace1 = p1;
*ptr = p1;
*p = p1;
}
}
else
{ aux=p1;
p2 = new(LISTA);
if(elemento<p1->info)
{ if(p1->enlace==aux)
{
*ptr=p2;
p2->info=elemento;
p2->enlace= p1;
p2->enlace1=p1;
p1->enlace =p2;
p1->enlace1=p2; }
else
{
*ptr=p2;
p2->info=elemento;
p2->enlace=p1;
aux1=*p;
aux1->enlace=p2;
p2->enlace1=aux1;
p1->enlace1=p2;
}}
else{
while(p1->enlace != aux)
{ aux1=p1->enlace;
if((p1->info<elemento&&elemento<aux1->info)||
(p1->info==elemento||elemento==aux1->info))
break;
else
p1 = p1->enlace;
}
if(p1->enlace==aux) {
p2->info = elemento;
p2->enlace = aux;
p1->enlace = p2;
p2->enlace1 = p1;
aux->enlace1 =p2;
*p = p2;
}
else {
p2->info=elemento;
aux1=p1->enlace;
p1->enlace=p2;
p2->enlace1=p1;
p2->enlace=aux1;
aux1->enlace1=p2;
}
}}
}
void orden(LISTA **ptr,LISTA **p)
{
LISTA *x3,*p1, *p2,*aux,*aux1,*x,*x1=NULL,*i=NULL,*j=NULL,*m;
char elemento;
x=*ptr;
x3=x;
if(*ptr!=NULL)
{
do{
p1=x1;
elemento=x->info;
if(p1==NULL)
{
p1=new(LISTA);
p1->info=elemento;
p1->enlace=p1;
p1->enlace1=p1;
i=p1;
j=p1;
x1=p1;
}
else{
p2=new(LISTA);
p2->info=elemento;
if(elemento<p1->info)
{
aux1=p1->enlace1;
p2->enlace=p1;
p1->enlace1=p2;
p2->enlace1=aux1;
aux1->enlace=p2;
i=p2;
x1=p2;
}
else{
while(p1->enlace!=x1)
{
aux=p1->enlace;
if((elemento>p1->info&&elemento<aux->info)||(elemento==p1->info))
break;
else
p1=p1->enlace;
}
if(p1->enlace!=x1)
{
p2->enlace=aux;
p2->enlace1=p1;
p1->enlace=p2;
aux->enlace1=p2;
}
else
if(p1->enlace==x1)
{
p2->enlace1=p1;
p1->enlace=p2;
p2->enlace=x1;
x1->enlace1=p2;
j=p2;
}
}
}
m=x->enlace;
delete(x);
x=m;
}
while(x!=x3);
printf("Ordenaci¢n con ‚xito");
*ptr=i;
*p=j;
}
else
printf("Lista Vac¡a");
}
void buscar_ele(LISTA **ptr,LISTA **p,char elemento)
{
LISTA *aux,*aux1;
aux=*ptr;
aux1=*p;
aux1=aux1
->enlace;
if(aux!=NULL){
while(aux->enlace!=aux1&&aux->info!=elemento){
aux=aux->enlace;
}
if(aux->info==elemento) {
printf("nnEl elemento es %c , ubicado en la posici¢n %p ",aux->info,aux);
}
else
printf("nnEl elemento no existe");
}
else
printf("nnLista vac¡a");
}
void mostrar_elementos(LISTA **ptr,LISTA **p)
{
LISTA *aux,*aux1,*aux2;
aux=*ptr;
aux1=*p;
aux1=aux1->enlace;
if(aux!=NULL){
printf("Los elementos son:nn");
while(aux->enlace!=aux1){
printf("El elemento %c , est ubicado en la posici¢n %p n",aux->info,aux);
aux=aux->enlace;
}
printf("El elemento %c , est ubicado en la posici¢n %p n",aux->info,aux);
}
else
printf("nnLista vac¡a");
}
# endif:D
-
si esto te puede servir mas bien como ejemplo y mirar como funcionan las listas...este ejemplo es de listas circulares
:
# ifndef PA_h
# define PA_h
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
#define TIPO int
typedef struct nodo
{
TIPO info;
struct nodo *enlace;
struct nodo *enlace1;
}LISTA;
int menu(void);
void inserta_final(LISTA **ptr, char elemento);
void inserta_or(LISTA **ptr,LISTA **p, char elemento);
void orden(LISTA **ptr,LISTA **p);
void elim_ele_lista(LISTA **ptr);
void buscar_ele(LISTA **ptr,LISTA **p, char elemento);
void mostrar_elementos(LISTA **ptr,LISTA **p);
void inserta_final(LISTA **ptr,LISTA **p, char elemento)
{
LISTA *p1, *p2,*aux;
p1 = *ptr;
if(p1 == NULL)
{
p1 = new(LISTA);
if (p1 != NULL)
{
p1->info = elemento;
p1->enlace = p1;
p1->enlace1 = p1;
*ptr = p1;
*p = p1;
}
}
else
{ aux=p1;
while(p1->enlace != aux)
p1 = p1->enlace;
p2 = new(LISTA);
if(p2 != NULL)
{
p2->info = elemento;
p2->enlace = aux;
p1->enlace = p2;
p2->enlace1 = p1;
aux->enlace1 =p2;
*p = p2;
}
}
}
int menu(void)
{
int car;
clrscr();
printf("n opcion 1 insertar final elementos en la lista ");
printf("n opcion 2 sacar un elemento de la lista");
printf("n opcion 3 insertar ordenadamente");
printf("n opcion 4 ordenar inserci¢n");
printf("n opcion 5 buscar elemento");
printf("n opcion 6 mostrar elementos");
printf("n opcion 7 Exitn");
do{
car=getche();
}while(car<49||car>55);
return car;
}
void elim_ele_lista(LISTA **ptr,LISTA **p)
{
LISTA *aux,*aux1,*aux2;
aux=*ptr;
if(aux!=NULL){
if(aux->enlace!=aux){
*ptr=aux->enlace;
aux1=*ptr;
aux1->enlace1=aux->enlace1;
aux2=*p;
aux2->enlace=aux1;
printf("nnEl elemento eliminado es %c",aux->info);
delete(aux);
}
else
{
printf("nnEl elemento eliminado es %c",aux->info);
delete(aux);
*ptr=NULL;
*p=NULL;
}
}
else
printf("Lista vac¡a");
}
void inserta_or(LISTA **ptr,LISTA **p, char elemento)
{
LISTA *p1, *p2,*aux,*aux1;
p1 = *ptr;
if(p1 == NULL)
{
p1 = new(LISTA);
if (p1 != NULL)
{
p1->info = elemento;
p1->enlace = p1;
p1->enlace1 = p1;
*ptr = p1;
*p = p1;
}
}
else
{ aux=p1;
p2 = new(LISTA);
if(elemento<p1->info)
{ if(p1->enlace==aux)
{
*ptr=p2;
p2->info=elemento;
p2->enlace= p1;
p2->enlace1=p1;
p1->enlace =p2;
p1->enlace1=p2; }
else
{
*ptr=p2;
p2->info=elemento;
p2->enlace=p1;
aux1=*p;
aux1->enlace=p2;
p2->enlace1=aux1;
p1->enlace1=p2;
}}
else{
while(p1->enlace != aux)
{ aux1=p1->enlace;
if((p1->info<elemento&&elemento<aux1->info)||
(p1->info==elemento||elemento==aux1->info))
break;
else
p1 = p1->enlace;
}
if(p1->enlace==aux) {
p2->info = elemento;
p2->enlace = aux;
p1->enlace = p2;
p2->enlace1 = p1;
aux->enlace1 =p2;
*p = p2;
}
else {
p2->info=elemento;
aux1=p1->enlace;
p1->enlace=p2;
p2->enlace1=p1;
p2->enlace=aux1;
aux1->enlace1=p2;
}
}}
}
void orden(LISTA **ptr,LISTA **p)
{
LISTA *x3,*p1, *p2,*aux,*aux1,*x,*x1=NULL,*i=NULL,*j=NULL,*m;
char elemento;
x=*ptr;
x3=x;
if(*ptr!=NULL)
{
do{
p1=x1;
elemento=x->info;
if(p1==NULL)
{
p1=new(LISTA);
p1->info=elemento;
p1->enlace=p1;
p1->enlace1=p1;
i=p1;
j=p1;
x1=p1;
}
else{
p2=new(LISTA);
p2->info=elemento;
if(elemento<p1->info)
{
aux1=p1->enlace1;
p2->enlace=p1;
p1->enlace1=p2;
p2->enlace1=aux1;
aux1->enlace=p2;
i=p2;
x1=p2;
}
else{
while(p1->enlace!=x1)
{
aux=p1->enlace;
if((elemento>p1->info&&elemento<aux->info)||(elemento==p1->info))
break;
else
p1=p1->enlace;
}
if(p1->enlace!=x1)
{
p2->enlace=aux;
p2->enlace1=p1;
p1->enlace=p2;
aux->enlace1=p2;
}
else
if(p1->enlace==x1)
{
p2->enlace1=p1;
p1->enlace=p2;
p2->enlace=x1;
x1->enlace1=p2;
j=p2;
}
}
}
m=x->enlace;
delete(x);
x=m;
}
while(x!=x3);
printf("Ordenaci¢n con ‚xito");
*ptr=i;
*p=j;
}
else
printf("Lista Vac¡a");
}
void buscar_ele(LISTA **ptr,LISTA **p,char elemento)
{
LISTA *aux,*aux1;
aux=*ptr;
aux1=*p;
aux1=aux1
->enlace;
if(aux!=NULL){
while(aux->enlace!=aux1&&aux->info!=elemento){
aux=aux->enlace;
}
if(aux->info==elemento) {
printf("nnEl elemento es %c , ubicado en la posici¢n %p ",aux->info,aux);
}
else
printf("nnEl elemento no existe");
}
else
printf("nnLista vac¡a");
}
void mostrar_elementos(LISTA **ptr,LISTA **p)
{
LISTA *aux,*aux1,*aux2;
aux=*ptr;
aux1=*p;
aux1=aux1->enlace;
if(aux!=NULL){
printf("Los elementos son:nn");
while(aux->enlace!=aux1){
printf("El elemento %c , est ubicado en la posici¢n %p n",aux->info,aux);
aux=aux->enlace;
}
printf("El elemento %c , est ubicado en la posici¢n %p n",aux->info,aux);
}
else
printf("nnLista vac¡a");
}
# endif:D
-
BORCA muchisimas gracias por todo, pero en realidad no eran listas eran punteros a estructuras, pero bueno no pasa nada muchas gracias.
UN BESAZO MUAKKKKK:D:D:D:D