Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include <stdlib.h>
- #include <locale.h>
- #include <windows.h>
- #define MAX 200
- struct tipo_lista{
- int cod;
- struct tipo_lista *prox;
- };
- struct tipo_lista *primeiro;
- struct tipo_lista *ultimo;
- void flvazia(){
- struct tipo_lista *aux;
- aux= (struct tipo_lista*)malloc(sizeof(struct tipo_lista));
- primeiro=aux;
- ultimo=primeiro;
- }
- int insere(int x){
- struct tipo_lista *aux;
- aux=(struct tipo_lista*)malloc(sizeof(struct tipo_lista));
- aux->cod=x;
- ultimo->prox;
- aux->prox=NULL;
- }
- void imprime(){
- struct tipo_lista *aux;
- aux=primeiro->prox;
- while(aux!=NULL){
- printf("item =%d", aux->cod);
- aux=aux->prox;
- }
- }
- void pesquisa(int x){
- struct tipo_lista *aux;
- int flag=0;
- aux=primeiro->prox;
- while(aux!=NULL){
- if (aux->cod==x){
- printf("encontrou %d", x);
- flag=1;
- aux=NULL;
- }
- else
- aux=aux->prox;
- }
- if (flag==0)
- printf("item%d nao encontrou",x);
- }
- main(){
- char op='2';
- int i, codigo;
- flvazia();
- while(op!='o'){
- printf("codigo");
- scanf("%d",&codigo);
- insere(codigo);
- printf("continuar?");
- op = getch();
- }
- imprime();
- printf("pesquisa");
- scanf("%d",&codigo);
- pesquisa(codigo);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment