Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<malloc.h>
- struct node{
- int code,price;
- struct node *left;
- struct node *right;
- };
- struct node *tree;
- void create_tree(struct node *tree){
- tree=NULL;
- }
- void menu(){
- printf("Soniem Cellular Phone\n");
- printf("~~~~~~~~~~~~~~~~~~~~~\n\n");
- printf("1. add new phone\n");
- printf("2. update phone price\n");
- printf("3. Inorder,Preorder,Postorder\n");
- printf("4. exit\n");
- }
- struct node *add(struct node *tree){
- struct node *newnode,*nodeptr,*parentptr;
- int harga,kode;
- do{
- printf("Input phone code S[1-9][0-9][0-9][0-9] : S");
- scanf("%d",&kode);
- }while(kode<1000||kode>9999);
- do {
- printf("input phone price[$50...$999]: ");
- scanf("%d",&harga);
- } while(harga<50 || harga>999);
- newnode=(struct node *)malloc(sizeof(struct node));
- newnode->code=kode;
- newnode->price=harga;
- newnode->left=NULL;
- newnode->right=NULL;
- if(tree==NULL){
- tree=newnode;
- tree->left=NULL;
- tree->right=NULL;
- }else{
- parentptr=NULL;
- nodeptr=tree;
- while(nodeptr!=NULL)
- {
- parentptr=nodeptr;
- if(kode<=tree->code){
- nodeptr=nodeptr->left;
- }else{
- nodeptr=nodeptr->right;
- }
- }
- if(kode<=tree->code){
- parentptr->left=newnode;
- }else{
- parentptr->right=newnode;
- }
- }
- return tree;
- }
- int main(){
- int pilih;
- do {
- menu();
- scanf("%d",&pilih );
- getchar();
- if (pilih == 1) {
- tree=add(tree);
- }else if(pilih == 2){
- }else if(pilih == 3){
- }
- }while(pilih !=4);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement