// Worst case insertion O(2*logn)
struct Node *insert(struct Node *root,int data)
{
	if(root == NULL)
		return create(data);
	if(data > root->data)
		root->right = insert(root->right,data);
	else
		root->left  = insert(root->left,data);
	root->height = max(height(root->left),height(root->right)) + 1;
	int balance = getbalance(root);
	// left left case
	if(balance >  1 && data < root->left->data)
		return rightRotation(root);
	else // left right case
	if(balance > 1 && data > root->left->data)
	{
		root->left = leftRotation(root->left);
		return rightRotation(root);
	}
	else // right-right case
	if(balance < -1 && data > root->right->data)
	{
		return leftRotation(root);
	}
	else // right left case;
	if(balance < -1 && data < root->right->data)
	{
		root->right = rightRotation(root->right);
		return leftRotation(root);
	}
	// no change required;
	return root;

}
void doCommands() {
	char buf1[BUFFER1SIZE];
	printf("Please input your command(sendBitcoins  getBalance  quit): ");
	while (1) {
		fgets(buf1, BUFFER1SIZE, stdin);
		if (!strncasecmp(buf1, "sendBitcoins", 12)) {
			sendBitcoin();
		} else if (!strncasecmp(buf1, "getBalance", 10)) {
			getbalance();
		} else if (!strncasecmp(buf1, "quit", 4)) {
			quit();
		} else {

		}
	}

}
  void getdata()
   {
	cleardevice();
	hidemouseptr();
	cleardevice();
	setcolor(GREEN);
	settextstyle(10,0,3);
	outtextxy(70,20,"OPENING A NEW ACCOUNT");
	get_user_info();
	showmouseptr();
	draw_button(400,410,465,440,1,"BACK");
	draw_button(475,410,540,440,1,"NEXT");
	if(check_next_button()==0)
	   return;
	hidemouseptr();
	cleardevice();
	getbalance();
	draw_button(400,410,465,440,1,"BACK");
	draw_button(475,410,540,440,1,"NEXT");
	if(check_next_button()==0)
	   return;
	hidemouseptr();
	cleardevice();
	show_next_form();
	read_card_id();

	cleardevice();
	fl_code.id[0]=cust.fname[0];
	fl_code.id[1]=cust.lname[0];
	fl_code.acc_no=cust.acc_no;
	abswrite(0,1,4,&fl_code);

	 passwd.code=fl_code;
	 randomize();
	 passwd.pass=random(9999)+1;
	 gotoxy(35,10);
	 printf("****%.4d****",passwd.pass);
	 border();
	 settextstyle(1,0,5);
	 outtextxy(75,50,"Your PIN number is");

	 ft=fopen("password.dat","rb+");
	 fseek(ft,0,SEEK_END);
	 fwrite(&passwd,sizeof(passwd),1,ft);

	 fp=fopen("cust.dat","rb+");
	 fseek(fp,0,SEEK_END);
	 fwrite(&cust,sizeof(cust),1,fp);

	 df=fopen("data.dat","rb+");
	 fseek(df,0,SEEK_SET);
	 fread(&data,sizeof(data),1,df);
	 data.acc_no=cust.acc_no+1;
	 fseek(df,0,SEEK_SET);
	 fwrite(&data,sizeof(data),1,df);

	 flushall();
	 fcloseall();
	 getch();
	 return;
  }