Advertisement
Thiagoccaufes

aula 16 de abril de 2015

Apr 16th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. /*
  2.  * auwe.c
  3.  *
  4.  *  Created on: 16/04/2015
  5.  *      Author: Aluno
  6.  */
  7. #include<stdio.h>
  8. #define max 10
  9. typedef struct lista{
  10.     int ultimo;
  11.     int itens[max];
  12. }Lista;
  13.  
  14.  
  15. int estaCheia ( Lista *l){
  16.     return l->itens[l->ultimo] = max;
  17.  
  18. }
  19.  
  20. void inserirElemento(Lista *l, int v){
  21.     if(estaCheia(l)){
  22.         printf("lista cheia!");
  23.     }
  24.     else{
  25.         l->itens[l->ultimo] = v;
  26.         l->ultimo ++;
  27.     }
  28. }
  29.  
  30.  
  31. int estaVazia ( Lista *l){
  32.     return(l->ultimo == 0);
  33. }
  34.  
  35. void criarLista( Lista *l ){
  36.     l->ultimo=0;
  37. }
  38.  
  39. void imprimeLista(Lista *l){
  40.     if(!estaVazia(l)){
  41.         int i;
  42.         for(i=0;i<l->ultimo;i++){
  43.             printf("%d ", l -> itens[i]);
  44.         }
  45.     }
  46.         else{
  47.             printf("estΓ‘ vazia");
  48.         }
  49.     }
  50. void removerElemento(int i, Lista* l){
  51.     if(i>= 0 && i < l->ultimo){
  52.         int x;
  53.         for(x=i; x < l-> ultimo ; x++){
  54.             l->itens[x-1]= l -> itens[x];
  55.         l -> ultimo --;
  56.         }
  57.     }
  58.     else{
  59.         printf("posicao invalida!");
  60.     }
  61.  
  62. }
  63.  
  64.  
  65. int main(){
  66.     Lista lista;
  67.     criarLista(&lista);
  68.     int x = estaVazia(&lista);
  69.    
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement