コード例 #1
0
ファイル: 12.c プロジェクト: Bminus/Algorithms
void searchi(struct node* root,int search)
{
	if(root!=NULL)
	{
	if(root->data==search)
	{
		printf("Element fOUND\n");
		if(root->left!=NULL && root->right!=NULL)
		{
			struct node* temp=root->right;
			while(temp->left!=NULL)
			{
				temp=temp->left;
			}
			int swap=root->data;
			root->data=temp->data;
			temp->data=swap;
			root=temp;
		}
		if(root->left==NULL && root->right==NULL)
		{
			if(root->par->left==root)
			{
				root->par->left=NULL;
			}
			else
				root->par->right=NULL;
		}
		else if(root->left!=NULL && root->right==NULL)
		{
			if(root->par->left==root)
			{
				root->par->left=root->left;
			}
			else
				root->par->right=root->left;
		}
		else if(root->left==NULL && root->right!=NULL)
		{
			if(root->par->left==root)
			{
				root->par->left=root->right;
			}
			else
				root->par->right=root->right;
		}
		

	}
	else if(root->data<search)
	{
		searchi(root->right,search);
	}
	else
		searchi(root->left,search);
	}
}
コード例 #2
0
ファイル: Zinc.cpp プロジェクト: developerRJ/Hindustan-Zinc
void bill()
{	ifstream file("emp.txt",ios::binary);
	client oob;

     long i;
	i=searchi();

	  if(i==0)
	  {
		cout<<"\n\n\n\t\t\t(PLEASE run option 1 of Menu bar)";
		file.close();
		return;
	      }

	while(!file.eof())
	{	file.read((char *)& oob,sizeof(client));
		if(oob.getcode()==i)
		break;
	}
	file.close();
	client ob1;
	strcpy(ob1.ename,oob.ename);
	strcpy(ob1.dept,oob.dept);
	strcpy(ob1.desig,oob.desig);
	strcpy(ob1.bname,oob.bname);
	ob1.sno=ob.sno+=1;
	ob1.billno=ob.billno+=1;
	ob1.nrmt=oob.nrmt;
	ob1.baccno=oob.baccno;
	ob1.empcd=i;
	cout<<"\n\n\t\t\tENTER BILL AMOUNT:-  \t";
	fflush(stdin);
	cin>>ob1.billamt;
	cout<<"\n\n\t\t\tENTER DEPENDENT CODE:-  \t";
	fflush(stdin);



		cout<<"\n\t\t\t\t ENTER h FOR SELF" ;
		cout<<"\n\t\t\t\t ENTER w FOR WIFE" ;
		cout<<"\n\t\t\t\t ENTER f FOR FATHER" ;
		cout<<"\n\t\t\t\t ENTER m FOR MOTHER" ;
		cout<<"\n\t\t\t\t ENTER s FOR SON" ;
		cout<<"\n\t\t\t\t ENTER d FOR DAUGHTER" ;
		cout<<"\n\t\t\t\t ENTER o FOR OTHER" ;

	      do{
		cout<<"\n\t\t\t ENTER CODE :";
		   cin>>ob1.dcode;



	   if(ob1.dcode=='l'||ob1.dcode=='w'|| ob1.dcode=='f'||ob1.dcode=='m'||ob1.dcode=='s'||ob1.dcode=='d' ||ob1.dcode=='o')
		    break;
	   else
	    {
	     cout<<"\n\n\t\tWRONG CHOICE\n\t\tENTER CORRECT OPTION...";
	    }
	}while(ob1.dcode!='l'||ob1.dcode!='w'|| ob1.dcode!='f'||ob1.dcode!='m'||ob1.dcode!='s'||ob1.dcode!='d' ||ob1.dcode!='o');



	cout<<"\n\n\t\t\tENTER BILLTYPE CODE:-  \t";
	fflush(stdin);
	cout<<"\n\t\t\t\t ENTER c FOR COMPANY's DOCTOR";
	cout<<"\n\t\t\t\t ENTER g FOR GOVT.DOCTOR";
	cout<<"\n\t\t\t\t ENTER r FOR REFERAL DOCTOR";
	cout<<"\n\t\t\t\t ENTER a FOR AYURVEDIC DOCTOR";
	cout<<"\n\t\t\t\t ENTER h FOR HOMEOPATHIC DOCTOR";
	cout<<"\n\t\t\t\t ENTER u FOR UNANI";
	cout<<"\n\t\t\t\t ENTER o FOR OTHER";


	 do {
		cout<<"\n\t\t\t ENTER CODE :";
		cin>>ob1.btcode;
		if(ob1.btcode=='c'||ob1.btcode=='g'||ob1.btcode=='r'||ob1.btcode=='a'||ob1.btcode=='h'||ob1.btcode=='u'||ob1.btcode=='o')
		  break;
		else
		{ cout<<"\n\n\t\t\tWRONG CHOICE\n\t\tENTER CORRECT OPTION";
		}
	  }while(ob1.btcode!='c'||ob1.btcode!='g'||ob1.btcode!='r'||ob1.btcode!='a'||ob1.btcode!='h'||ob1.btcode!='u'||ob1.btcode!='o');

	time_t now= time(0);
	tm *ptr=localtime(&now);
	asctime(ptr);
	ob1.t.tm_sec=ptr->tm_sec;
	ob1.t.tm_min=ptr->tm_min;
	ob1.t.tm_hour=ptr->tm_hour;
	ob1.t.tm_mday=ptr->tm_mday;
	ob1.t.tm_mon=ptr->tm_mon;
	ob1.t.tm_year=ptr->tm_year;
	ofstream o("emp.txt",ios::app|ios::binary);
	o.write((char*)&ob1,sizeof ob1);
	o.close();
	}