⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 binaryt.bak

📁 c compiler with added projects...
💻 BAK
字号:
struct Node
{

	int val;
	struct Node *left;
	struct Node *right;
	struct Node *parent;

};


void main()
{
	int option,count=0,countd=0,i;
	struct Node *root='\0';
	struct Node *current='\0';
	struct Node *temp='\0';



	while(option!=5)
	{
			clrscr();
			printf("Prees 1 for Add\n");
			printf("Press 2 for Show\n");
			printf("Press 3 for Deletion");
			printf("Press 5 for Quit");
			printf("COUNT %d ",count);

			scanf("%d",&option);

			if(option==1)
			{
				current = (struct Node *) malloc(sizeof(struct Node));
				current->left=current->right=current->parent='\0';
				printf("Enter Value");
				scanf("%d",&current->val);

				if(root=='\0')
				{
					root=current;
					count++;
					countd++;
				}
				else
				{
					temp=root;
					while(1)
					{
						if(current->val>temp->val)
							if(temp->right=='\0')
							{
								temp->right=current;
								current->parent=temp;
								count++;
								countd++;
								break;
							}
							else
							temp=temp->right;

						if(current->val<=temp->val)
							if(temp->left=='\0')
							{
								temp->left=current;
								current->parent=temp;
								count++;
								countd++;
								break;
							}
							else
							temp=temp->left;

					}

				}
			} //1st IF statment end

			if(option==2)
			{
				count=countd;
				temp=root;

			while(1)
			{
				  if((count==1)&&(temp->parent=='\0'))
						{
							printf("Value of Node is %d  ",temp->val);
							break;
						}
						else
						{
							while(1)
							{
								if((temp->left=='\0')&&(temp->right=='\0'))
								break;

								if(temp->left!='\0')
									  temp=temp->left;
									  else
									  temp=temp->right;
							}
						}

					current=temp;
					current=current->parent;
					printf("Value of Node is %d  ",temp->val);

					if(temp->val<=current->val)
						current->left='\0';
					else
						current->right='\0';
						count--;
						temp=current;
				}
			getch();

			}//2nd IF statment end

			if(option==5)
			{
				temp=root;

			while(1)
			{
				  if((countd==1)&&(temp->parent=='\0'))
						{
							printf("Value of Node is %d Deleted ",temp->val);
							free(temp);
							break;
						}
						else
						{

							while(1)
							{
								if((temp->left=='\0')&&(temp->right=='\0'))
								break;

								if(temp->left!='\0')
									  temp=temp->left;
									  else
									  temp=temp->right;
							}
						}

					current=temp;
					current=current->parent;
					printf("Value of Node is %d  ",temp->val);

					if(temp->val<=current->val)
						current->left='\0';
					else
						current->right='\0';
						free(temp);
						countd--;
						temp=current;
				}
			getch();
				printf("ALLAH Hafiz");
				getch();
				break;
			}
	}	//Main while loop end
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -