Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  liste
Language: C/C++
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

struct nod
{
      int info;
      nod *urm;
};
nod *p,*u;

void creare()
{
     if(p==NULL)
     {
          p=new nod;
          printf("Prima informatie din lista este: ");
          scanf("%d",&p->info);
          u=p;
     }
}

void adaug_incep()
{
     nod *q;
     if(p==NULL)
          creare();
     else
     {
          q=new nod;
          printf("Prima informatie din lista este: ");
          scanf("%d",&q->info);
          q->urm=p;
          p=q;
     }
}

void adaug_sf()
{
     if(p==NULL)
          creare();
     else
     {
          nod *q;
          q=new nod;
          printf("Informatia este: ");
          scanf("%d",&q->info);
          u->urm=q;
          u=q;
          u->urm=NULL;
     }
}

void afisare()
{
     nod *r;
     for(r=p;r;r=r->urm)
          printf("%d",r->info);
     printf("\n");
}
int main()
{
     int opt;
     do
     {
        printf("1.Creare\n");
        printf("2.Adaugare la inceputul listei\n");
        printf("3.Adaugare la sfarsitul listei\n");
        printf("4.Afisare lista\n");
        printf("0.Exit\n");
        printf("Dati optiunea: ");
        scanf("%d",&opt);
     }while(opt!=0);

     switch(opt)
     {
       case 1:
          {
             creare();
             break;
          }
      case 2:
          {
             adaug_incep();
             break;
          }

      case 3:
          {
             adaug_sf();
             break;
          }

      case 4:
          {
             afisare();
             break;
          }
  
     
     }

}
          
Comments: