2008.2 UERN Natal Estrutura de Dados

Professor: Aquiles Burlamaqui
email: moc.liamg|iuqamalrubseliuqa#moc.liamg|iuqamalrubseliuqa

Links

Notas

Ementa

  • Introdução.
  • Alocação Dinâmica.
  • Pilhas
  • Filas.
  • Árvores.
  • Árvores balanceadas.
  • Tabelas de dispersão.
  • Busca.
  • Complexidade

Agenda

Data Conteúdo Trabalho
03/11/2008 AULA 01(4) - Apresentação da Disciplina e Revisão
10/11/2008 AULA 02(8) - Ponteiros
17/11/2008 AULA 03(12) - Pilha
24/11/2008 AULA 04(16) - Laboratório Pilha & CIA T1
01/12/2008 ,, - Não Haverá AULA
08/12/2008 AULA 05(20) - Fila T2
15/12/2008 AULA 06(24) - Prova e Entrega dos Exercícios E1

Pontos

Ediane - 1,0
Diogo - 1,0
Pedro - 1,0
Mônica - 2,0
Gustavo - 1,0

Códigos

stack.h

typedef struct element {
   int value;
   struct element* next;
} element;
 
typedef struct stack {
   int size;
   struct element* top;
} stack;
 
void push(stack * s, int v);
 
int pop(stack * s);

stack.c

#include <stdio.h>
#include "stack.h"
 
void push(stack * s, int i) {
   if(s->size == 0) {
      s->top = malloc(sizeof(element));
      s->top->value = i;
      s->top->next = NULL;
      s->size++;
   } else {
      element * temp;
      temp = s->top;
      s->top = malloc(sizeof(element));
      s->top->next = temp;
      s->top->value = i;
      s->size++;
   }
}
 
int pop(stack * s) {
  if(s->size==0) {
     printf("Pilha Vazia!");
     return -1;
  } else {
     s->size--;
     element * temp =  s->top;
     s->top = temp->next;
     return temp->value;
  }
}
 
int main() {
   stack pilha;
   pilha.size = 0;
   pilha.top = NULL;
   printf("pop:%i\n", pop(&pilha));
   push(&pilha, 10); 
   push(&pilha, 15); 
   push(&pilha, 40); 
   printf("pop:%i\n", pop(&pilha));
   printf("pop:%i\n", pop(&pilha));
   printf("pop:%i\n", pop(&pilha));
   printf("pop:%i\n", pop(&pilha));
}
Add a New Comment
or Sign in as Wikidot user
(will not be published)
- +
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.