#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>
#define Nil NULL
#define info(p) p->info
#define next(p) p->next
#define first(l) (l)
typedef int infotype;
typedef struct telmlist*address;
typedef struct telmlist {
infotype info;
address next;
} elmtlist;
typedef address list;
void makesenarai(list *l)
{
first(*l) = Nil; }
list nodbaru (int m) {
list n;
n = (list) malloc(sizeof(elmtlist));
if (n != NULL) {
info(n) = m;
next(n) = Nil;}
return n; }
void insertsenarai (list *l, list t, list p)
{
if (p==Nil) {
t->next = *l;
*l = t; }
else {
t->next = p->next;
p->next = t; }
}
void printsenarai(list l)
{
list ps;
for (ps=l; ps!=Nil; ps=ps->next) {
cout<<" "<<info(ps)<<" -->"; }
cout<<"null"<<endl;
}
int main ()
{
list pel;
list n;
int i,k,nilai;
makesenarai(&pel);
cout<<"Masukan Banyak Data = ";
cin>>k;
for (i=1;i<=k;i++) {
cout<<"Masukan Data Senarai ke-"<<i<<" = ";
cin>>nilai;
n=nodbaru(nilai);
insertsenarai(&pel,n,NULL); }
printsenarai(pel) ;
return 0;
}
#include<iostream.h>
#include<stdlib.h>
#define Nil NULL
#define info(p) p->info
#define next(p) p->next
#define first(l) (l)
typedef int infotype;
typedef struct telmlist*address;
typedef struct telmlist {
infotype info;
address next;
} elmtlist;
typedef address list;
void makesenarai(list *l)
{
first(*l) = Nil; }
list nodbaru (int m) {
list n;
n = (list) malloc(sizeof(elmtlist));
if (n != NULL) {
info(n) = m;
next(n) = Nil;}
return n; }
void insertsenarai (list *l, list t, list p)
{
if (p==Nil) {
t->next = *l;
*l = t; }
else {
t->next = p->next;
p->next = t; }
}
void printsenarai(list l)
{
list ps;
for (ps=l; ps!=Nil; ps=ps->next) {
cout<<" "<<info(ps)<<" -->"; }
cout<<"null"<<endl;
}
int main ()
{
list pel;
list n;
int i,k,nilai;
makesenarai(&pel);
cout<<"Masukan Banyak Data = ";
cin>>k;
for (i=1;i<=k;i++) {
cout<<"Masukan Data Senarai ke-"<<i<<" = ";
cin>>nilai;
n=nodbaru(nilai);
insertsenarai(&pel,n,NULL); }
printsenarai(pel) ;
return 0;
}