lunes, 2 de julio de 2012
Colas con enteros c++
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <todas.h>
#define MAX 100
void datos (void)
{
system("color 6");
int a=15,b=8;
gotoxy (a,b);
printf ("Edith Juarez Juarez \n\n");
int c=20,d=5;
gotoxy (c,d);
printf ("Grupo 351\n\n");
for(int x=3;x<=40;x++){
gotoxy(x,3);
printf("*");
}
for(int x=3;x<=40;x++){
gotoxy(x,10);
printf("*");
}
// getch();
}
char *p[MAX];
char *crecup(void);
void calmac(char *c);
int spos, rpos;
void intro(void);
void revisar(void);
void borrar(void);
int main(void)
{
datos();
char s[MAX];
register int t;
spos=0;
rpos=0;
for(t=0; t<MAX; ++t) p[t]=NULL;
for(;;)
{
printf("\n1.-Introducir\n2.-Revisar,\n3.-Borrar\n4.- Salir\n");
printf("\nEscriba el numero\n\n");
gets(s);
*s=toupper(*s);
switch(*s)
{
case'1':intro(); break;
case'2':revisar(); break;
case'3':borrar(); break;
case'4':exit(0); break;
}
}
return 0;
}
void intro(void)
{
char s[MAX], *p;
do
{
printf("\nDigite el numero %d:\n", spos+1);
gets(s);
system("cls");
if(*s=='\0')break;
p=(char*)malloc(strlen(s)+1);
if(!p)
{
printf("No hay memoria reservada\n");
return;
}
strcpy(p,s);
calmac(p);
}
while(*s);
}
void revisar(void)
{
int t;
if(rpos==spos)
{
printf("No hay datos\n");
return;
}
for(t=rpos; t<spos; t++)
printf("\nNumero %d: %s\n", t+1, p[t]);
}
void borrar(void)
{
char *q;
q=crecup();
if(q==NULL)
{
printf("No hay datos\n");
return;
}
printf("Este es el dato recuperado y borrado: Dato numero %d: %s\n", rpos+1, q);
free(q);
}
void calmac(char *q)
{
if(spos==MAX)
{
printf("\nlA COLA ESTA LLENA\n");
return;
}
p[spos]=q;
spos++;
}
char *crecup(void)
{
if(rpos==spos)
{
printf("\nNo hay datos\n");
return NULL;
}
rpos++;
return p[rpos-1];
}
Suscribirse a:
Enviar comentarios (Atom)

No hay comentarios:
Publicar un comentario