AYUDA!!!! metodo ordenacion burbuja con listas
buenas, tengo que hacer un programa que me ordene por el metodo de burbuja, el programa ya lo tengo pero con arreglos dinamicos, el problema esque ahora me lo piden con listas y no se usar listas, no se si alguno me pudiera ayudar con esto, aqui les dejo el programa de ordenamiento con burbuja pero con arreglos, de antemano muchas gracias, espero alguien pueda ayudarme ah hacerlo.
#include<systimeb.h>
#include<ctype.h>
#include<dos.h>
#include<time.h>
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include <time.h>
struct timeb TomaTiempo(void);
float dif(struct timeb,struct timeb);
void main(void)
{
for(;;)
{
int i,n,opc,x,y,m;
int oper;
clrscr();
gotoxy(5,5);printf("**************************************************************");
gotoxy(5,6);printf("* METODO DE INTERCAMBIO (BURBUJA O BUBBLE SORT) *");
gotoxy(5,7);printf("* MENU *");
gotoxy(5,8);printf("**************************************************************");
gotoxy(5,9);printf("* *");
gotoxy(5,10);printf("* 1) Generar los elementos a ordenar. *");
gotoxy(5,11);printf("* 2) Realizar el ordenamiento por este metodo. *");
gotoxy(5,12);printf("* 3) Salir *");
gotoxy(5,13);printf("* *");
gotoxy(5,14);printf("**************************************************************");
gotoxy(5,15);printf(" OPCION: ");
scanf("%d",&opc);
switch (opc)
{
case 1:
clrscr();
gotoxy(5,7);printf("Cuantos Datos Desea Que Se Ordenen: ");
gotoxy(5,8);printf("NOTA: Los numero se generaran aleatoriamente");
gotoxy(40,7);scanf("%d",&n);
int *p;
p = (int*) malloc( sizeof(int) * n );
randomize();
m=0;
do
{
m++;
p[m]=rand();
}while(m<n);
m=0;
printf("nnnttARREGLOn");
do
{
printf("%d | ",p[m]);
m++;
}while(m<n);
getch();
break;
case 2:
float Tiempo;
struct timeb tiempo1,tiempo2;
tiempo1=TomaTiempo();
clrscr();
int aux,r;
m=0;
printf("nn");
do
{
printf("%d |",p[m]);
m++;
}while(m<n);
printf("nANTESn");
for(r=0; r<n; r++)
{
for(m=0; m<n; m++)
{
if (p[m] > p[m+1])
{
aux=p[m+1];
p[m+1]=p[m];
p[m]=aux;
oper++;
}
};
};
m=0;
tiempo2=TomaTiempo();
Tiempo=dif(tiempo1,tiempo2);
do
{
printf("%d |",p[m]);
m++;
}while(m<n);
printf("nDESPUES");
printf("nnt El Tiempo En El Cual Se Tardo En Arreglarlo Fue: %fnn", Tiempo);
printf("tEl Numero De Operaciones Realizada Fue De %d",oper);
getch();
break;
case 3:
exit(1);
break;
}
}
}
float dif(struct timeb tiempo1,struct timeb tiempo2)
{
int seg;
unsigned int miliseg;
miliseg=(tiempo2.millitm-tiempo1.millitm);
seg=tiempo2.time-tiempo1.time;
if((tiempo2.millitm<tiempo1.millitm))
{
miliseg=miliseg+1000;
seg=seg-1;
}
return (seg+(miliseg/(float)1000));
}
struct timeb TomaTiempo(void)
{
char *tzstr = "TZ=PST8PDT";
struct timeb t;
putenv(tzstr);
tzset();
ftime(&t);
return t;
}
#include<systimeb.h>
#include<ctype.h>
#include<dos.h>
#include<time.h>
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include <time.h>
struct timeb TomaTiempo(void);
float dif(struct timeb,struct timeb);
void main(void)
{
for(;;)
{
int i,n,opc,x,y,m;
int oper;
clrscr();
gotoxy(5,5);printf("**************************************************************");
gotoxy(5,6);printf("* METODO DE INTERCAMBIO (BURBUJA O BUBBLE SORT) *");
gotoxy(5,7);printf("* MENU *");
gotoxy(5,8);printf("**************************************************************");
gotoxy(5,9);printf("* *");
gotoxy(5,10);printf("* 1) Generar los elementos a ordenar. *");
gotoxy(5,11);printf("* 2) Realizar el ordenamiento por este metodo. *");
gotoxy(5,12);printf("* 3) Salir *");
gotoxy(5,13);printf("* *");
gotoxy(5,14);printf("**************************************************************");
gotoxy(5,15);printf(" OPCION: ");
scanf("%d",&opc);
switch (opc)
{
case 1:
clrscr();
gotoxy(5,7);printf("Cuantos Datos Desea Que Se Ordenen: ");
gotoxy(5,8);printf("NOTA: Los numero se generaran aleatoriamente");
gotoxy(40,7);scanf("%d",&n);
int *p;
p = (int*) malloc( sizeof(int) * n );
randomize();
m=0;
do
{
m++;
p[m]=rand();
}while(m<n);
m=0;
printf("nnnttARREGLOn");
do
{
printf("%d | ",p[m]);
m++;
}while(m<n);
getch();
break;
case 2:
float Tiempo;
struct timeb tiempo1,tiempo2;
tiempo1=TomaTiempo();
clrscr();
int aux,r;
m=0;
printf("nn");
do
{
printf("%d |",p[m]);
m++;
}while(m<n);
printf("nANTESn");
for(r=0; r<n; r++)
{
for(m=0; m<n; m++)
{
if (p[m] > p[m+1])
{
aux=p[m+1];
p[m+1]=p[m];
p[m]=aux;
oper++;
}
};
};
m=0;
tiempo2=TomaTiempo();
Tiempo=dif(tiempo1,tiempo2);
do
{
printf("%d |",p[m]);
m++;
}while(m<n);
printf("nDESPUES");
printf("nnt El Tiempo En El Cual Se Tardo En Arreglarlo Fue: %fnn", Tiempo);
printf("tEl Numero De Operaciones Realizada Fue De %d",oper);
getch();
break;
case 3:
exit(1);
break;
}
}
}
float dif(struct timeb tiempo1,struct timeb tiempo2)
{
int seg;
unsigned int miliseg;
miliseg=(tiempo2.millitm-tiempo1.millitm);
seg=tiempo2.time-tiempo1.time;
if((tiempo2.millitm<tiempo1.millitm))
{
miliseg=miliseg+1000;
seg=seg-1;
}
return (seg+(miliseg/(float)1000));
}
struct timeb TomaTiempo(void)
{
char *tzstr = "TZ=PST8PDT";
struct timeb t;
putenv(tzstr);
tzset();
ftime(&t);
return t;
}
