Jump to content
Sign in to follow this  
nickname_rejected

Boleh Tolong X?

Recommended Posts

Menu

1.Input item bagi pokok dedua

2.Cari suatu item

3.Cari bapa untuk item semasa

4.Hapus item

5.Cetak mengikut preorder

6.Cetak mengikut inorder

7.Cetak mengikut postorder

8.Cari nod yg terbesar dlm pokok

9.Cari nod yg terkecil dlm pokok

10.Cari purata nilai dlm pokok

11.Berapakah bilangan nod dlm pokok

12.Cari anak kiri dan anak kanan bg suatu item

13.Gambaran/rajah pokok gelintiran dedua

14.Keluar

Pengisytiharan Pembolehubah

typedef struct nod {

int data;

struct nod *aKiri, *aKanan;

}NOD;

NOD *akar, *locPtr, *bapa, *nodBaru;

Cipta Pokok Kosong

void ciptaPokok()

{

akar = NULL;

}

void inputData()

{

nodBaru = (NOD*)malloc(sizeof(NOD));

scanf(“%dâ€,&nodBaru->data);

}

Tentukan Pokok Kosong

int pokokKosong()

{

if (akar == NULL)

return(1);

else

return(0);

}

Gelintar Nod

int gelintarNod()

{

int jumpa = 0;

inputData();

locPtr = akar;

bapa = NULL;

while (!jumpa && locPtr != NULL)

if (nodBaru->data < locPtr->data) {

bapa = locPtr;

locPtr = locPtr->aKiri;

}

else if (nodBaru->data > locPtr->data) {

bapa = locPtr;

locPtr = locPtr->aKanan;

}

else

jumpa = 1;

return(jumpa);

}

Tambah Nod

void tambahNod()

{

int jumpa;

jumpa = gelintarNod();

if (jumpa)

printf(“\nData telah wujud !â€);

else {

nodBaru->aKiri = NULL;

nodBaru->aKanan = NULL;

if (pokokKosong())

akar = nodBaru;

else

if (nodBaru->data < bapa->data)

bapa->aKiri = nodBaru;

else

bapa->aKanan = nodBaru;

}

}

Hapus Nod

void hapusNod()

{

NOD *p, *temp;

int jumpa;

jumpa = gelintarNod();

if (!jumpa)

printf(“Nod tidak wujud …â€);

else {

/* hapus nod yang mempunyai 2 anak */

if ((locPtr->aKiri != NULL) && (locPtr->aKanan != NULL)) {

p = locPtr->aKanan;

bapa = locPtr;

while (p->aKiri != NULL) {

bapa = p;

p = p->aKiri;

}

locPtr->data = p->data;

locPtr = p;

}

/* hapus nod daun atau nod yang mempunyai 1 anak */

temp = locPtr->aKiri;

if (temp == NULL)

temp = locPtr->aKanan;

if (bapa == NULL)

akar = temp;

else if (bapa->aKiri == locPtr)

bapa->aKiri = temp;

else

bapa->aKanan = temp;

}

}

Boleh tolong aku x setelkan prog ni?

Share this post


Link to post
Share on other sites

Sindrom Ahli Forum Baru (new forumer syndrom) ialah daftar sebagai ahli, kemudian bukak new thread, akhir sekali buat moderator sakit hati dan tanpa teragak-agak untuk buang terus thread tersebut. Saya berjanji ini adalah kali terakhir untuk berkompromi. Selepas ni, topik macam akan dibuang tanpa notis.

Sila baca peraturan forum sebelum berforum (Please read and follow the forum's rules and regulations before starting new thread or posting to any thread).

Oleh yang demikian, sila sunting/edit post anda secepat mungkin.

Share this post


Link to post
Share on other sites

aku rasa kenal sape ko ni..

ni soalan projek ni....

woi buat sendiri lah. xpon ko ambik je orang dah siap. lambat lagi nak. pose pun x abih lagi.

mmg payah aku try test dah tp masih x jadi2. hehehehehhe :lol::lol::lol:

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...