Well, okay then - if you want - here is my program. I wrote it but I don't understand it so who can help me (maybe by changing names and putting some comments)?
Code:
// Labs005.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
struct s {
double d;
struct s *p;
};
struct s *inite(struct s *h);
struct s *pute(struct s *h);
void gete(struct s *h);
void removee(struct s *h);
int _tmain(int argc, _TCHAR* argv[])
{
struct s *h;
h=NULL;
h=inite(h);
pute(h);
gete(h);
removee(h);
system("PAUSE");
return 0;
}
struct s *inite(struct s *h) {
struct s *p;
p = (struct s *) malloc(sizeof(struct s));
if (p==NULL) printf("Pointer error");
printf("Enter value: ");
scanf("%lf", &(p->d));
p->p=h;
return p;
}
struct s *pute(struct s *h) {
struct s *p, *q;
p = (struct s *) malloc(sizeof(struct s));
if (p==NULL) printf("Pointer error");
p->p=NULL;
printf("Enter value: ");
scanf("%lf", &(p->d));
if(h==NULL) return p;
else {
q=h;
while (q->p!=NULL) q=q->p;
q->p=p;
return h;
}
}
void gete(struct s *h) {
while (h!=NULL) {
printf("\n%lf", h->d);
h=h->p;
}
printf("\n");
}
void removee(struct s *h) {
struct s *p;
while (h!=NULL) {
p=h;
h=h->p;
free(p);
}
free(h);
}
I know it seems strange that i wrote it without understanding it but it's true... :?