Home » »

Posted by CB Blogger


Nama :aperius giawa

Npm    :13110160

Kelas  :TI-P1302

 

#include <iostream.h>
#include <stdlib.h>
#include <malloc.h>
#include <conio.h>

#define nil NULL
#define info(P) P->info
#define next(P) P->next
#define first(L) (L)

typedef int infotype;
typedef struct telmlist *alamat;
typedef struct telmlist
{
            infotype info;
   alamat next;
}elmtlist;

typedef alamat list;

void buatsenarai(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 sisipsenarai (list *L, list t, list p)
      {
            if (p==nil)
         {
         t->next=*L;
         *L=t;
         }
         else
         {
            t->next=p->next;
            p->next=t;
            }
            }

            void cetaksenarai (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;

         buatsenarai(&pel);
            cout<<" Masukkan Banyak data = ";
         cin>>k;
         for (i=1;i<=k;i++)
         {
            cout<<" Masukkan Data Senarai ke-"<<i<<" = ";
            cin>>nilai;
            n=nodbaru(nilai);
            sisipsenarai (&pel,n,NULL);
            }

            cetaksenarai(pel);
            getch();
            return 0;
            }




 


Diberdayakan oleh Blogger.

Silhak Pilih Materi Favorit Anda

Populer