Home > database >  Computer data structure make contacts
Computer data structure make contacts

Time:10-23

Solving problems and modify, children can't change come over
#include
#include
#include
Struct address
{//define structure
Char name [10].
Char street [50];
Char city [10].
Char nation [15].
Char tel [7];
Struct address * next;//subsequent pointer
The prior struct address *;//precursor pointer
}
Struct address * start;//the first node
Struct address * last;//end node
Struct address * find (char *);//declare lookup function
Void the enter ();//function declaration
Void the search ();
Void the save ();
Void the load ();
Void list ();
Void ddelete (struct address * * start, struct address * * last);
Void insert (struct address * I, struct address * * start, struct address * * last);
Void inputs (char *, char *, int);
Void the display (struct address *);
Int menu_select (void);
Void main ()
{
Start last==NULL;
For (;; )
{
The switch (menu_select ())
{
Case1: enter ();
continue;
Case2: ddelete (& amp; Start, & amp; The last);
continue;
Case3: list ();
continue;
Case4: search ();
continue;
Case5: save ();
continue;
Case6: the load ();
continue;
Case7: exit (0);
}
}
}
Int menu_select (void)//home directory
{
Char s [80];
Int c;
Printf (" * * * * * * * * ^ ^ welcome to use DOS directory system * * * * * * * * * \ n ");
Printf (" * * * * * * * * please lead before other operations into * * * * * * * * * * \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" * * * * * * * * * 1 input information * * * * * * * * * * \ n ");
Printf (" * * * * * * * * * 2 delete information * * * * * * * * * * \ n ");
Printf (" * * * * * * * * * 3 shows information * * * * * * * * * * \ n ");
Printf (" * * * * * * * * * 4 find * * * * * * * * * * * * * * \ n ");
Printf (" * * * * * * * * * 5 save * * * * * * * * * * * * * * \ n ");
Printf (" * * * * * * * * * 6 import * * * * * * * * * * * * \ n ");
Printf (" * * * * * * * * * 7 out of * * * * * * * * * * * * \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Do {
Printf (" \ n both Please enter you choice: \ n ");
gets(s);
C=atoi (s);
} while (c<0 | | c> 7);
return c;//return the input value
}
Void the enter ()//input function, this function input data, when the input name is empty out
{
Struct address * info;//definition of the current node
For (;; )
{
Info=(struct) address * malloc (sizeof (struct adress));//space for distribution of the current node
if(! Info)
{
Printf (" \ n Out of memory ");
The exit (0);//allocate space failure, exit the program
}
Printf (" input empty name end: \ n ");
Inputs (" please input your name: ", info - & gt; The name, 10);
if(! The info - & gt; The name [0]) break;//if the input name is empty, end cycle
Inputs (" please enter the street: ", info - & gt; Street, 50);
Inputs (" please enter the city, ", info - & gt; City, 15);
Inputs (" please enter the nation, ", info - & gt; Nation, 15);
Inputs (" please enter the telephone: ", info - & gt; Tel, 7);
Insert (info, & amp; Start, & amp; The last);//call nodes insertion function
}
}
Void inputs (char * prompt, char * s, int count)//input function, crossing the line detection function
{
Char [255] p;
Do
{print (prompt);
The fgets (p, 254, stdin);
If (strlen (p) & gt; The count)
Printf (" \ nToo Long \ n ");
}
While (strlen (p) & gt; The count);
P [strlen (p) - 1)=0.
Strcpy (s, p);
}
Void insert (struct address * I, struct address * * start, struct address * * last)
//data insertion function
{
If (* last==NULL)//if the end node is empty, means that the current list is empty
{
I - & gt; Next=NULL;
I - & gt; The prior=NULL;
* last=I;
* start=I;
return;
}
The else
{
(* last) - & gt; Next=I;
I - & gt; The prior=* last;
I - & gt; Next=NULL;
* last=(* last) - & gt; Next;
}
}
Void ddelete (struct address * * start, struct address * * last)//delete function
{
Struct address * info;
Char s [80];
Inputs (" please input your name." , s, 10);//input to remove node name domain content
Info=find (s);//find the content
If (info)//if found
{
Printf (" Deleting... \n");
If (* start==info)//if the nodes, led, put the node displacement as the first node (entrance) as a new
{
* start=info - & gt; Next;
Start the if (*)
(* start) - & gt; The prior=NULL;
The else * last=NULL;
}
The else//if you would like to delete the nodes is not the first
{
The info - & gt; The prior - & gt; Next=info - & gt; Next;/* to the nodes of the precursor after next pointer to the node displacement, and makes the nodes after flooding the prior advice to the precursor of */
If (info!=* last)//if the node is end node, has made the node precursor for end node
The info - & gt; Next - & gt; The prior=infor - & gt; The prior;
The else
* last=info - & gt; The prior;
}
Free (info);//release the memory by the node
Printf (" - OK, deleted successfully! \n");
}
}
Struct address * find (char * name)//lookup function, parameter is to find the node name field
{
Struct address * info;
Info=start;
While (info)
{
if(! STRCMP (name, info - & gt; Name))
Return the info;
Info=info - & gt; Next;
}
Printf (" did not find relevant information, \ n ");
return NULL;
}//output the entire list
Void list (void)
{
Struct address * info;
Info=start;
If (info==NULL)
Printf (" the current record is empty!" );
Else printf (" street name \ t \ \ t t \ \ t t city nation phone \ t \ n ");
While (info)
{
The display (info);
If (info - & gt; Next==NULL) {break; } the info=info - & gt; Next;
}
Printf (" \ n \ n ");
}
Void the display (struct address * info)//output incoming node function
{
Printf (" % s \ t ", info - & gt; Name);
Printf (" % s \ t ", info - & gt; Street);
Printf (" % s \ t ", info - & gt; City);
Printf (" % s \ t ", info - & gt; Nation);
Printf (" % s \ t ", info - & gt; Tel);
printf("\n");
}
Void search (void)//lookup function
{
Char name [40].
Struct address * info;
Printf (" input to find the name: ");//to enter search name
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related