Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Lib Agenda

Lib Agenda

Ratings: (0)|Views: 2|Likes:
Published by api-3703319

More info:

Published by: api-3703319 on Oct 17, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

#include <stdio.h>
#include <string.h>
#define list_size 200

typedef struct{
char list[list_size][60];
int contactindex;
int listindex;
}nameslist;

typedef struct{
char list[list_size][15];
int contactindex;
int listindex;
}phonelist;

typedef struct{
char list[list_size][40];
int contactindex;
int listindex;
}maillist;

typedef struct{
char *name;
char *phone,*cellphone;
char *mail;
}person;

typedef struct{
char person[list_size];
int listindex;
}personlist;

static nameslist names;
static phonelist phonenums, cellphonenums;
static maillist mailaddr;
static person contact;
static personlist contactlist;

static void initlists(){
names.listindex=-1;
phonenums.listindex=-1;
cellphonenums.listindex=-1;
mailaddr.listindex=-1;

};

static void insertdata(int index,person contact){
int i;
if (names.listindex>=0)
{for (i=names.listindex;i>=index;i--)

{strcpy(names.list[i+1],names.list[i]);

strcpy(phonenums.list[i+1],phonenums.list[i]);
strcpy(cellphonenums.list[i+1],cellphonenums.list[i]);
strcpy (mailaddr.list[i+1],cellphonenums.list[i]);

};

};
strcpy(names.list[index],contact.name);
strcpy(phonenums.list[index],contact.phone);
strcpy(cellphonenums.list[index],contact.cellphone);
strcpy(mailaddr.list[index],contact.mail);
names.listindex++;
phonenums.listindex++;
cellphonenums.listindex++;
mailaddr.listindex++;

};

static void removedata(int index){
int i;
if (names.listindex>=0)
{for (i=index;i<names.listindex;i++)

{strcpy(names.list[i],names.list[i+1]);

strcpy(phonenums.list[i],phonenums.list[i+1]);
strcpy(cellphonenums.list[i],cellphonenums.list[i+1]);
strcpy(mailaddr.list[i],mailaddr.list[i+1]);

};names.listindex--;

phonenums.listindex--;
cellphonenums.listindex--;
mailaddr.listindex--;

};
};
static void getdata(int index){

strcpy(contact.name,names.list[index]);
strcpy(contact.phone,phonenums.list[index]);
strcpy(contact.cellphone,cellphonenums.list[index]);
strcpy(contact.mail,mailaddr.list[index]);

};

/*retorna -(\u00edndice de entrada do novo nome) se o nome n\u00e3o for encontrado.
se for encontrado retorna o \u00edndice do nome*/
static int binaryresearch(char name[],int start,int end){

int mid;
mid=(start+end)/2;
if (strcmp(names.list[start],name)==0)
{return start;

};
if (strcmp(names.list[mid],name)==0)
{return mid;

};
if (strcmp(names.list[end],name)==0)
{return end;

}
else
{if (strcmp(names.list[mid],name)>0)
{if (start==mid)
{/*fixme: quando o nome n\u00e3o era encontrado e o \u00edndice de entrada
deste novo nome deveria ser 0, o programa falhava feio, ent\u00e3o, agora o

programa retona -201 para esses casos.*/
if (mid==0)
{

return -201;
};

return -1*(mid);
};
end=mid-1;
return binaryresearch(name,start,end);

}else

{
if (start==mid)
{

return -1*(mid+1);
};
start=mid+1;
return binaryresearch(name,start,end);

};
};
};
/*retorna 1 se o nome j\u00e1 estiver na lista*/
int insertcontact(person contact){
int entranceindex;
entranceindex=binaryresearch(contact.name,0,names.listindex);
if (entranceindex>=0)
{
return 1;

};
if (entranceindex==-201)
{

entranceindex=0;
};

entranceindex=-1*(entranceindex);
if (names.listindex==-1)
{

entranceindex=0;
};
insertdata(entranceindex,contact);
return 0;

};

person getcontact(char name[]){
person localcontact;
int contactindex;

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->