Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct nodo{
- int dato;
- struct nodo*siguiente;
- };
- void agregar(struct nodo**ultimo,struct nodo*primero){
- int a;
- if((*ultimo)==NULL){
- primero=ultimo;
- (*ultimo)=malloc(sizeof(struct nodo));
- printf("Ingrese el dato a agregar\n");
- scanf("%d",&a);
- (*ultimo)->dato=a;
- (*ultimo)->siguiente=NULL;
- system("pause");
- }
- else{
- struct nodo*temporal=malloc(sizeof(struct nodo));
- (*ultimo)->siguiente=malloc(sizeof(struct nodo));
- temporal=(*ultimo)->siguiente;
- ultimo=temporal;
- printf("Ingrese el dato a agregar\n");
- scanf("%d",&a);
- (*ultimo)->dato=a;
- system("pause");
- }
- }
- void buscar(struct nodo*ultimo,struct nodo*primero){
- int b,aux;
- struct nodo*auxi;
- printf("Ingrese el dato a buscar\n");
- scanf("%d",&b);
- if(ultimo==NULL){
- printf("La lista esta vacia\n");
- system("pause");
- return;}
- else
- for(auxi=primero;auxi==NULL;auxi=auxi->siguiente){
- //auxi->siguiente=malloc(sizeof(struct nodo));
- if(auxi->dato==b)
- aux++;
- printf("a\n");
- }
- if(aux==0)
- printf("el dato no esta en la lista\n");
- else
- printf("el dato esta en la lista");
- system("pause");
- }
- void mostrar(struct nodo*ultimo,struct nodo*primero){}
- int main()
- {
- struct nodo *ultimo=NULL;
- struct nodo *primero=NULL;
- int op;
- while(1){
- system("cls");
- printf("1-Agregar nro\n2-Mostrar\n3-Buscar\n4-Salir\nIngresar opcion:");
- scanf("%d",&op);
- switch(op){
- case 1:system("cls");
- agregar(&ultimo,primero);
- break;
- case 2:system("cls");
- mostrar(ultimo,primero);
- break;
- case 3:system("cls");
- buscar(ultimo,primero);
- break;
- case 4:exit(0);
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement