Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct lista{
- int info;
- struct lista *prox;
- }Lista;
- Lista *lst_cria(){
- return NULL;
- }
- Lista *lst_insere (Lista *l, int i ){
- Lista *novo = (Lista*) malloc(sizeof(Lista));
- novo->info = i;
- novo->prox = l;
- return novo;
- }
- void lst_imprime(Lista* l){
- Lista* p = l;
- for (p=l; p!=NULL; p=p->prox){
- printf("info = %d\n", p->info);
- }
- }
- int maiores (Lista* lst, int n){
- Lista* p;
- int maior=0;
- for (p=lst; p!=NULL;p=p->prox){
- if(p->info>n){
- maior++;
- }
- }
- return maior;
- }
- Lista* retira_n(Lista* lst, int n){
- Lista* p=lst;
- Lista* ant=NULL;
- if(p==NULL)
- { return lst;}
- if(ant==NULL)
- {lst=p->prox;}
- else
- {
- for (p=lst;p!=NULL;p->prox){
- ant=p;
- p=p->prox;
- if(p->info==n);
- { ant->prox = p->prox;
- p=ant; }
- }
- free(p);
- return lst;
- }
- }
- int main(void){
- Lista *l;
- Lista *m;
- int aux;
- l= lst_cria();
- m=lst_cria();
- l= lst_insere(l, 10);
- l= lst_insere(l, 54);
- l= lst_insere(l, 23);
- lst_imprime(l);
- printf("\n");
- printf("retirei o 23\n");
- printf("\n");
- l=retira_n(l, 23);
- lst_imprime(l);
- aux=maiores(l, 3);
- printf("maior: %i\n",aux);
- lst_imprime(l);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment