list ... with problems

I am a beginner in C++ and needs help ...The program required the user to input integers until input 0; the program must be displayed first- then even numbers and than - odd numbers.Using a list and if the number is even we put it before the first node:prim else ( odd number) we put after the last odd node - ultim. It displays my latest number with all the waters parcurg(prim)

Below is the code:

#include<iostream.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

const unsigned NMAX=100;
struct nod {unsigned nr, urm;};
unsigned liber[NMAX+1], nr_el;
nod lista[NMAX+1];

void init(unsigned &, unsigned &);
int este_plina();
int este_vida(unsigned );
int alloc_mem();
void adaug_prim_nod(unsigned &, unsigned &, int);
unsigned adaug_inainte_prim(unsigned , int);
unsigned adaug_dupa_ultim(unsigned , int);
void parcurg(unsigned);

int main()
{
unsigned prim, ultim, n;
init(prim, ultim);
cout<<"nr sunt:"<<endl; cout<<"nr="; cin>>n;
if(n!=0)
{ adaug_prim_nod(prim, ultim,n);
cout<<"nr="; cin>>n;
while(n!=0 && ! este_plina() )
{ if(n%2==0) prim = adaug_inainte_prim(prim, n);
else ultim= adaug_dupa_ultim(ultim, n);
cout<<"nr="; cin>>n;} }
if(!este_vida(prim))
{ cout<<"nr sunt:";
parcurg(prim);}
else cout<<"nu am nr"; }
void init(unsigned &prim, unsigned &ultim)
{ prim=ultim=NULL;
for(int k=1;k<=NMAX;k++)
liber[k]=1;}
int este_plina()
{ return nr_el==NMAX;}
int este_vida(unsigned prim)
{ return prim=NULL; }
int alloc_mem()
{ for(int k=1; !liber[k];k++)
liber[k]=0;nr_el++;}
void adaug_prim_nod(unsigned &prim,unsigned &ultim, int n)
{ prim=ultim=1;
liber[1]=0;
nr_el=1;
lista[prim].nr=n; lista[prim].urm=NULL;}
unsigned adaug_inainte_prim(unsigned prim, int n)
{ int p;
p=alloc_mem();
lista[p].nr=n;
lista[p].urm=prim;
return p;}
unsigned adaug_dupa_ultim(unsigned ultim, int n)
{ int p;
p = alloc_mem();
lista[p].nr=n;
lista[p].urm=NULL;
lista[ultim].urm=p;
return p;}
void parcurg(unsigned p)
{ cout<<lista[prim].nr<<'\t'<<";" ;
while(p!=NULL)
{ cout<<lista[p].nr<<" ";
p=lista[p].urm; }
}
well your first problems are you're using iostream.h... just use iostream.
Also you should either add using namespace std; or using std::cout; using std::cin; using std::endl; etc. Or use std::cout<<....

For the rest of the code: I don't get your question really, and it'd help if you'd post your code properly (spaces and tabs added where needed and put code brackets around it), cuz this is illegible.

Cheers!
Topic archived. No new replies allowed.