Un apuntador es una variable que solamente almacena direcciones de memoria, se llama apuntador, pointer o puntero, por que a traves de esa variable, se puede llegar a otra variable, para que se pueda definir un apuntador, debe ser del mismo tipo a la variable que va a apuntar, por ejemplo
int clave, y quiero declarar un apuntador que apunte a esta variable se declara con el mismo tipo
int *ptr.
Cuando se declara una variable, se le dice al compilador a traves del sistema operativo que resrve un espacio de memoria y le asigne un nombre.
.
Programacion
miércoles, 25 de septiembre de 2013
lunes, 23 de septiembre de 2013
Resolucion de Examen
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
void main(void)
{
int temo=0, 1, num[6];
int *ptr;
for (i=0; i <= 5; i++)
{temp = temp +5-i;
num[i] = temp;}
ptr = &num[0];
for (i = 0; i <= 5; i++)
{printf("\n %d, %p", num[i], ptr);
ptr++;}
ptr = &num[0];
}
Diagramas en el cuaderno e.e
Estatus de la evaluacion, ir pensando en recursar o en el extra
#include <iostream.h>
#include <conio.h>
void main(void)
{
int temo=0, 1, num[6];
int *ptr;
for (i=0; i <= 5; i++)
{temp = temp +5-i;
num[i] = temp;}
ptr = &num[0];
for (i = 0; i <= 5; i++)
{printf("\n %d, %p", num[i], ptr);
ptr++;}
ptr = &num[0];
}
Diagramas en el cuaderno e.e
Estatus de la evaluacion, ir pensando en recursar o en el extra
lunes, 9 de septiembre de 2013
Programa de Lista
#include <conio.h>
#include <stdio.h>
#include <windows.h>
#include <ctype.h>
#include <stdlib.h>
struct lista {
int clave;
char descrip[25];
struct lista *sigptr; };
typedef struct lista LISTA;
typedef LISTA *LSTPTR;
void enlista(LSTPTR *iniptr, LSTPTR *finptr, int cla, char descr[25])
{ LSTPTR nvoptr, actptr, otroptr;
nvoptr = (LSTPTR) malloc(sizeof(LISTA));
if (nvoptr != NULL)
{nvoptr->clave = cla;
strcpy(nvoptr->descrip, descr);
nvoptr->sigptr = NULL;
if (*iniptr == NULL)
{*iniptr = nvoptr;
*finptr = nvoptr;
}
else
{actptr = *iniptr;
if (cla < (*iniptr)->clave)
{nvoptr->sigptr = *iniptr;
*iniptr = nvoptr;
}
else
if (cla > (*finptr)->clave)
{(*finptr)->sigptr = nvoptr;
*finptr = nvoptr;
}
else
{otroptr = actptr->sigptr;
while (cla > otroptr->clave)
{actptr= actptr->sigptr;
otroptr= actptr->sigptr;
}
actptr->sigptr = nvoptr;
nvoptr->sigptr = otroptr;
}
}
}
else
printf("%d no fue insertado. No hay memoria disponible\n\n", cla);
}
void menu(void)
{ system("cls");
printf("\n\n\n\n"
" OPERACIONES DISPONIBLES EN LA LISTA ORDENADA: \n\n\n\n"
" 1 AGREGAR UN ELEMENTO A LA LISTA\n"
" 2 IMPRIMIR LA LISTA\n"
" 3 EXTRAER UN ELEMENTO DE LA LISTA\n"
" 4 SALIR DEL PROGRAMA\n");
}
main()
{ LSTPTR iniptr = NULL, finptr = NULL;
char opcion, descri[25];
int clav;
menu();
printf("\n Elige opcion: ");
scanf("%c", &opcion);
while (opcion != '4')
{ switch(opcion)
{ case '1': printf("\n Clave del articulo (entero): ");
scanf("%d", &clav);
fflush(stdin);
printf("\n Descripcion del articulo : ");
gets(descri);
enlista(&iniptr, &finptr, clav, descri) ;
break;
default : printf("\n\n Opcion no valida.....");
printf("\n\n Enter para continuar...");
getch();
break;
}
menu();
fflush(stdin);
printf("\n Elige opcion: ");
scanf("%c", &opcion);
}
printf("\n Fin del programa.\n\n");
printf(" Enter para terminar...");
getch();
}
miércoles, 28 de agosto de 2013
Filas o Colas
FiFo
first in first out
si se compara una fila, se tiene un aountador que esta apuntando al tope de esa fila, y entre sus nodos se crean enlases, y el primero que entro a la pila, es nulo, y de esa manera se van haciendo los enlances, en la cola, vamos a suponer que se tiene estos nodos que se van a encolar,
first in first out
si se compara una fila, se tiene un aountador que esta apuntando al tope de esa fila, y entre sus nodos se crean enlases, y el primero que entro a la pila, es nulo, y de esa manera se van haciendo los enlances, en la cola, vamos a suponer que se tiene estos nodos que se van a encolar,
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
struct colanodo {
int clave;
char descrip[20];
struct colanodo *sigptr;};
typedef struct colanodo COLANODO;
typedef COLANODO *COLANODOPTR;
void enqueue(COLANODOPTR *, COLANODOPTR *, int, char[]);
void menu(void);
main()
{ COLANODOPTR adelaptr = NULL, atrasptr = NULL;
int opcion, clav;
char descri[20];
menu();
printf("\n Elige opcion: ");
scanf("%d", &opcion);
while (opcion != 4)
{ switch(opcion)
{ case 1: printf("\n INSERCION EN LA COLA");
printf("\n\n Clave del articulo: ");
scanf("%d", &clav);
fflush(stdin);
printf("\n Descripcion del articulo: ");
gets(descri);
enqueue(&adelaptr, &atrasptr, clav, descri);
break;
default : printf("\n Opcion no permitida.\n\n");
printf(" Enter para continuar...");
getch();
menu();
break;
}
menu();
printf("\n Elige opcion: ");
scanf("%d", &opcion);
}
printf("\n Fin del programa.\n\n");
printf("\n Enter para salir...");
getch();
}
void menu(void)
{ system("cls");
printf("\n\n\n\n"
" OPERACIONES DISPONIBLES CON LA COLA: \n\n\n\n"
" 1 (enqueue) AGREGAR UN DATO A LA COLA\n"
" 2 (dequeue) ELIMINAR UN DATO DE LA COLA\n"
" 3 IMPRIMIR LA COLA\n"
" 4 SALIR DEL PROGRAMA\n");
}
void enqueue(COLANODOPTR *adelaptr, COLANODOPTR *atrasptr, int cla, char desc[20])
{ COLANODOPTR nvoptr;
nvoptr = (COLANODOPTR) malloc(sizeof(COLANODO));
if (nvoptr != NULL) {
nvoptr->clave = cla;
strcpy(nvoptr->descrip, desc);
nvoptr->sigptr = NULL;
if (*adelaptr==NULL)
*adelaptr = nvoptr;
else
(*atrasptr)->sigptr = nvoptr;
*atrasptr = nvoptr;
}
else
printf("%c %s no fue insertado. No hay memoria disponible\n\n", cla, desc);
}
lunes, 26 de agosto de 2013
Pila, a medias, no lo acabe -.-
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
struct pilanodo {
int clave;
char descrip[20];
struct pilanodo *sigptr;
};
typedef struct pilanodo PILANODO;//redefinicion pila
typedef PILANODO *PILANODOPTR;//redefinicion apuntador
void push(PILANODOPTR *, int, char[]);
void instrucciones(void);
void listar(PILANODOPTR);
main()
{ PILANODOPTR pilaptr = NULL;
int opcion, cve;
char desc[20];
instrucciones();
printf("\n Elige opcion: ");
scanf("%d", &opcion);
while (opcion != 4)
{ switch(opcion)
{ case 1: printf("\n Escribe la clave del articulo (entero): ");
scanf("%d", &cve);
fflush(stdin);
printf("\n Escribe la descripcon del articulo: ");
gets(desc);
push(&pilaptr, cve, desc);//direccion de pilaptr(&pilaptr)
break;
case 3: listar(pilaptr);
break;
default : printf("\n Opcion no permitida. \n\n");
printf("\n Enter para continuar...");
getch();
instrucciones();
}
instrucciones();
printf("\n Elige opcion: ");
scanf("%d", &opcion);
}
printf("\n Fin del programa.\n\n");
printf(" Enter para salir...");
getch();
}
void push(PILANODOPTR *topeptr, int cve, char des[20])// *topeptr apunta a pilaptr
{ PILANODOPTR nuevoptr;//como no se va a modificar no se pone *
nuevoptr = (PILANODOPTR) malloc(sizeof(PILANODO));
if (nuevoptr != NULL)
{ nuevoptr->clave = cve;
strcpy(nuevoptr->descrip, des);
nuevoptr->sigptr = *topeptr;//en estas 2 lineas se intercambian los valores del apyuntador
*topeptr = nuevoptr;
}
else
{ printf("\n %d %s, no fue insertado."
"\n No hay memoria disponible. \n", cve, des);
printf("\n Enter para continuar...");
getch();
}
}
void listar (PILANODOPTR auxptr)
{
if(auxptr==NULL)
printf("\n\n La pila esta vacia");
else
{while(auxptr->sigptr!=NULL)
{
printf("\n %d%s",auxptr->clave,auxptr->descrip);
auxptr=auxptr->sigptr;
}
}
}
void instrucciones(void)
{ system("cls");
printf(" \n\n\n\n"
" OPERACIONES DISPONIBLES CON LA PILA: \n\n\n\n"
" 1 (push) INSERTAR UN VALOR EN LA PILA \n"
" 2 (pop) EXTRAER UN VALOR DE LA PILA \n"
" 3 IMPRIMIR LA PILA \n"
" 4 SALIR DEL PROGRAMA \n");
}
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
struct pilanodo {
int clave;
char descrip[20];
struct pilanodo *sigptr;
};
typedef struct pilanodo PILANODO;//redefinicion pila
typedef PILANODO *PILANODOPTR;//redefinicion apuntador
void push(PILANODOPTR *, int, char[]);
void instrucciones(void);
void listar(PILANODOPTR);
main()
{ PILANODOPTR pilaptr = NULL;
int opcion, cve;
char desc[20];
instrucciones();
printf("\n Elige opcion: ");
scanf("%d", &opcion);
while (opcion != 4)
{ switch(opcion)
{ case 1: printf("\n Escribe la clave del articulo (entero): ");
scanf("%d", &cve);
fflush(stdin);
printf("\n Escribe la descripcon del articulo: ");
gets(desc);
push(&pilaptr, cve, desc);//direccion de pilaptr(&pilaptr)
break;
case 3: listar(pilaptr);
break;
default : printf("\n Opcion no permitida. \n\n");
printf("\n Enter para continuar...");
getch();
instrucciones();
}
instrucciones();
printf("\n Elige opcion: ");
scanf("%d", &opcion);
}
printf("\n Fin del programa.\n\n");
printf(" Enter para salir...");
getch();
}
void push(PILANODOPTR *topeptr, int cve, char des[20])// *topeptr apunta a pilaptr
{ PILANODOPTR nuevoptr;//como no se va a modificar no se pone *
nuevoptr = (PILANODOPTR) malloc(sizeof(PILANODO));
if (nuevoptr != NULL)
{ nuevoptr->clave = cve;
strcpy(nuevoptr->descrip, des);
nuevoptr->sigptr = *topeptr;//en estas 2 lineas se intercambian los valores del apyuntador
*topeptr = nuevoptr;
}
else
{ printf("\n %d %s, no fue insertado."
"\n No hay memoria disponible. \n", cve, des);
printf("\n Enter para continuar...");
getch();
}
}
void listar (PILANODOPTR auxptr)
{
if(auxptr==NULL)
printf("\n\n La pila esta vacia");
else
{while(auxptr->sigptr!=NULL)
{
printf("\n %d%s",auxptr->clave,auxptr->descrip);
auxptr=auxptr->sigptr;
}
}
}
void instrucciones(void)
{ system("cls");
printf(" \n\n\n\n"
" OPERACIONES DISPONIBLES CON LA PILA: \n\n\n\n"
" 1 (push) INSERTAR UN VALOR EN LA PILA \n"
" 2 (pop) EXTRAER UN VALOR DE LA PILA \n"
" 3 IMPRIMIR LA PILA \n"
" 4 SALIR DEL PROGRAMA \n");
}
Pilas
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
struct pilanodo {
int clave;
char descrip[20];
struct pilanodo *sigptr;
};
typedef struct pilanodo PILANODO;
typedef PILANODO *PILANODOPTR;
void push(PILANODOPTR *, int, char[]);
void instrucciones(void);
main()
{ PILANODOPTR pilaptr = NULL;
int opcion, cve;
char desc[20];
instrucciones();
printf("\n Elige opcion: ");
scanf("%d", &opcion);
while (opcion != 4)
{ switch(opcion)
{ case 1: printf("\n Escribe la clave del articulo (entero): ");
scanf("%d", &cve);
fflush(stdin);
printf("\n Escribe la descripcon del articulo: ");
gets(desc);
push(&pilaptr, cve, desc);
break;
default : printf("\n Opcion no permitida. \n\n");
printf("\n Enter para continuar...");
getch();
instrucciones();
}
instrucciones();
printf("\n Elige opcion: ");
scanf("%d", &opcion);
}
printf("\n Fin del programa.\n\n");
printf(" Enter para salir...");
getch();
}
void push(PILANODOPTR *topeptr, int cve, char des[20])
{ PILANODOPTR nuevoptr;
nuevoptr = (PILANODOPTR) malloc(sizeof(PILANODO));
if (nuevoptr != NULL)
{ nuevoptr->clave = cve;
strcpy(nuevoptr->descrip, des);
nuevoptr->sigptr = *topeptr;
*topeptr = nuevoptr;
}
else
{ printf("\n %d %s, no fue insertado."
"\n No hay memoria disponible. \n", cve, des);
printf("\n Enter para continuar...");
getch();
}
}
void instrucciones(void)
{ system("cls");
printf(" \n\n\n\n"
" OPERACIONES DISPONIBLES CON LA PILA: \n\n\n\n"
" 1 (push) INSERTAR UN VALOR EN LA PILA \n"
" 2 (pop) EXTRAER UN VALOR DE LA PILA \n"
" 3 IMPRIMIR LA PILA \n"
" 4 SALIR DEL PROGRAMA \n");
}
miércoles, 21 de agosto de 2013
Pilas
Las pilas son un conjunto ordenado de objetos o nodos, los cuales pueden trabajarse uno a la ves, se llaman pilas por que los nodos se van apilando. Las pilas se trabajan bajo el concepto conocido como LIFO(Last in First out)
definimos una estructura de datos tipo pila
struct pilanodo
{int dato;
struct pilamodo * sigptr;
}
typedef struct pilanodo PILANODO;
typedef PILANODO *PILANODOPTR;
PILANODO var;
struct pilanodo *ptr;
PILANODO *PTR;
PILANODOPTR *pilaptr;
pilaptr = NULL
if(pilaptr==NULL)
PILANODOPTR *nuevoptr;
if (nuevoptr = (PILANODOPTR) malloc (sizeof(PILANODO)))
------------------------------------------------
main() | pilaptr=NULL |
| -Incersion |
| -palabra que no entendi por la |
| letra del profe -.- |
------------------------------------------------
definimos una estructura de datos tipo pila
struct pilanodo
{int dato;
struct pilamodo * sigptr;
}
typedef struct pilanodo PILANODO;
typedef PILANODO *PILANODOPTR;
PILANODO var;
struct pilanodo *ptr;
PILANODO *PTR;
PILANODOPTR *pilaptr;
pilaptr = NULL
if(pilaptr==NULL)
PILANODOPTR *nuevoptr;
if (nuevoptr = (PILANODOPTR) malloc (sizeof(PILANODO)))
------------------------------------------------
main() | pilaptr=NULL |
| -Incersion |
| -palabra que no entendi por la |
| letra del profe -.- |
------------------------------------------------
Suscribirse a:
Entradas (Atom)