CONTOH PROGRAM SISIP LIST PADA C++
CONTOH PROGRAM SISIP LIST PADA C++
PROGRAM:#include <iostream>
#include <stdio.h>
#include <malloc.h>
using namespace std;
typedef struct node{
int data;
struct node *next;
}NOD, *NODPTR;
void buatlist(NODPTR *s){
*s=NULL;
}
NODPTR NodBaru(int m){
NODPTR n;
n=(NODPTR) malloc(sizeof(NOD));
if(n!=NULL){
n->data=m;
n->next=NULL;
}
return n;
}
void insertlist(NODPTR*s, NODPTR t, NODPTR p){
if(p==NULL){
t->next=*s;
*s=t;
}
else{
t->next=p->next;
p->next=t;
}
}
void cetaklist(NODPTR s){
NODPTR ps;
for(ps=s;ps != NULL;ps=ps->next){
cout << " " << ps ->data<<"-->"<<endl;
}
}
int main(){
NODPTR pel;
NODPTR n;
buatlist(&pel);
n=NodBaru(55);
insertlist(&pel, n, NULL);
n=NodBaru(75);
insertlist(&pel, n, NULL);
n=NodBaru(60);
insertlist(&pel, n, NULL);
n=NodBaru(20);
insertlist(&pel, n, NULL);
n=NodBaru(33);
insertlist(&pel, n, NULL);
cetaklist(pel);
return 0;
}
FLOWCHART :