The text in printf and the variables are in Romanian
#include%26lt;iostream%26gt;
#include%26lt;conio.h%26gt;
using namespace std;
struct nod{
char nume[50];
char adresa[50];
char telefon[15];
nod *next;
};
void aDD(nod *%26amp;first)
{
nod *p=new nod;
cout%26lt;%26lt;"Intorduceti datele:"%26lt;%26lt;endl;
cout%26lt;%26lt;"Nume:";
cin%26gt;%26gt;p-%26gt;nume;
cout%26lt;%26lt;"Adresa:";
cin%26gt;%26gt;p-%26gt;adresa;
cout%26lt;%26lt;"Numar telefon :";
cin%26gt;%26gt;p-%26gt;telefon;
if(first==NULL)
{
first=p;
first-%26gt;next=NULL;
}
else
{
if(strcmp(first-%26gt;nume,p-%26gt;nume)%26gt;0)
{
p-%26gt;next=first;
first=p;
}
else
{
nod *q=first;
while(q-%26gt;next!=NULL%26amp;%26amp;strcmp(q-%26gt;next-...
q=q-%26gt;next;
cout%26lt;%26lt;q-%26gt;nume;
if(q-%26gt;next==NULL)
{
q-%26gt;next=p;
cout%26lt;%26lt;"dasdas";
p-%26gt;next=NULL;
}
else
{
p-%26gt;next=q-%26gt;next;
q-%26gt;next=p;
}
}
}
}
void print(nod *prim)
{
while(prim!=NULL)
{
cout%26lt;%26lt;prim-%26gt;nume%26lt;%26lt;endl;
prim=prim-%26gt;next;
}
}
void del(nod *%26amp;first)
{
if(first!=NULL)
{
char deSters[50];
cout%26lt;%26lt;"Abonatul pe care vreti sa il stregeti(nume):";
cin%26gt;%26gt;deSters;
if(!strcmp(first-%26gt;nume,deSters))
{
nod *p=first;
first=first-%26gt;next;
p-%26gt;next=NULL;
free(p);
}
else
{
nod *p=first;
while(p-%26gt;next!=NULL%26amp;%26amp;strcmp(p-%26gt;next-...
p=p-%26gt;next;
if(p-%26gt;next!=NULL)
{
nod*s=p-%26gt;next;
p-%26gt;next=s-%26gt;next;
s-%26gt;next=NULL;
cout%26lt;%26lt;s-%26gt;nume;
free(s);
}
else
cout%26lt;%26lt;"Abonatul tastat nu exista in DB\n";
}
}
else
cout%26lt;%26lt;"Lista nu contine nici o informatie\n";
}
void printt(nod *prim)
{
if(prim!=NULL)
{
char abb[50];
cout%26lt;%26lt;"Abonatul a carui numar il cautati:";
cin%26gt;%26gt;abb;
while(prim%26amp;%26amp;strcmp(prim-%26gt;nume,abb))
prim=prim-%26gt;next;
if(prim==NULL)
cout%26lt;%26lt;"Abonatul nu exista in DB\n";
else
cout%26lt;%26lt;"Abonatul "%26lt;%26lt;abb%26lt;%26lt;" are numarul de telefon:"%26lt;%26lt;prim-%26gt;telefon%26lt;%26lt;endl;
}
else
cout%26lt;%26lt;"Lista abonatilor nu contine nici o inregisrare\n";
}
void printtt(nod *prim)
{
if(prim!=NULL)
{
char abb[50];
cout%26lt;%26lt;"Introduceti numarul persoanei cautate:";
cin%26gt;%26gt;abb;
while(prim%26amp;%26amp;strcmp(prim-%26gt;telefon,abb...
prim=prim-%26gt;next;
if(prim==NULL)
cout%26lt;%26lt;"Numarul de telefon nu exista in DB\n";
else
cout%26lt;%26lt;"Numarul de telefon "%26lt;%26lt;abb%26lt;%26lt;" apartine abonatului "%26lt;%26lt;prim-%26gt;nume%26lt;%26lt; "si locuieste la adresa "%26lt;%26lt;prim-%26gt;adresa%26lt;%26lt;endl;
}
else
cout%26lt;%26lt;"Lista abonatilor nu contine nici o inregisrare\n";
}
void main()
{
nod *prim=NULL;
char opt;
do
{
cout%26lt;%26lt;"\n1-adaugarea unui nou abonat\n";
cout%26lt;%26lt;"2-afisarea intregii liste \n";
cout%26lt;%26lt;"3-scoaterea din evidenta a unui abonat\n";
cout%26lt;%26lt;"4-afisarea numarului de telefon al unui abonat \n";
cout%26lt;%26lt;"5-afisarea datelor unui abonat cu un numar dat \n";
cout%26lt;%26lt;"Optiune:";
cin%26gt;%26gt;opt;
switch(opt)
{
case '1':aDD(prim);
break;
case '2'://cout%26lt;%26lt;prim-%26gt;next;
print(prim);
break;
case '3':del(prim);
break;
case '4':printt(prim);
break;
case '5':printtt(prim);
break;
}
}while(opt!='x');
}
Can u give me a sample program bout linked list and structure in C?
For Structure
/* The mechanism of a structure */
/* Define a type "person" to include
- forename and surname
- age and childcount */
typedef struct {
char forename[20];
char surname[20];
float age;
int childcount;
} person;
int main (int argc, int *argv) {
/* Create two persons */
person jimmy, flossie;
float avage;
/* Fill up each of the persons with information */
strcpy(jimmy.forename,"James");
strcpy(jimmy.surname,"Conway");
jimmy.age = 32.0;
jimmy.childcount = 2;
strcpy(flossie.forename,"Florence");
strcpy(flossie.surname,"Conway");
flossie.age = 21.0;
flossie.childcount = 2;
/* Calculate the average age of the persons */
avage = (flossie.age + jimmy.age) / 2.0;
/* Print out the persons names and the average age */
printf ("About %s and %s ...\n",flossie.forename,
jimmy.forename);
printf ("Their average age is %.2f\n",avage);
return 0;
}
/* st1.c
Sample output
[graham@saturday c]$ ./st1
About Florence and James ...
Their average age is 26.50
[graham@saturday c]$
*/
and for LinkedList refer this
http://www.codepedia.com/1/LinkedList
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment