...collaborate on

Makefile

prog.exe : prog.o lista.o
    gcc -o prog.exe prog.o lista.o

prog.o : prog.c lista.h
    gcc -c prog.c

lista.o : lista.h lista.c
    gcc -c lista.c


lista.h

#ifndef _LISTA
#define _LISTA

typedef struct sInteiro
  {
    int valor;
    struct sInteiro * seg;
  } Nodo, *Lista;

Lista inserir( int v, Lista l );
void listar( Lista l );
void listar_inv( Lista l );
Lista procurar( int v, Lista l );
int conta_elems( Lista l );

#endif


lista.c

#include "lista.h"
#include <stdio.h>

Lista inserir( int v, Lista l )
{
  Lista novo;

  novo = (Lista) malloc(sizeof(Nodo));
  novo->valor = v;
  novo->seg = l;

  return novo;
}


void listar( Lista l )
{
  if(l)
  {
    printf("%d ",l->valor);
    listar(l->seg);
  }
}

Lista inserir_ord( int v, Lista l)
{
  Lista novo;


  if((!l) || (l->valor > v))
  {
    novo = (Lista) malloc(sizeof(Nodo));
    novo->valor = v;
    novo->seg = l;
    return novo;
  }
  else
  {
    l->seg = inserir_ord(v,l->seg);
    return l;
  }
}


prog.c

#include <stdio.h>
#include "lista.h"

int main()
{
  Lista li=NULL;
  int i=0;

  while ((i+=3) < 100)
    li = inserir(i,li);

  listar(li);

  return 0;
}

r2 - 20 May 2004 - 18:20:15 - JoseCarlosRamalho
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
Syndicate this site RSSATOM