smalarg.c

来自「splitting of linked list」· C语言 代码 · 共 78 行

C
78
字号
#include<stdio.h>
#include<conio.h>
#include"treelib.c"

int small(node **root)
{
 node *temp;
 temp=*root;
 if(temp==NULL)
 {
   printf("tree is empty\n");
   return NULL;
 }
 else
 {
  while(temp->left!=NULL)
    temp=temp->left;
  return(temp->info);
 }
}

int large(node **root)
{
 node *temp;
 temp=*root;
 if(temp==NULL)
 {
   printf("tree is empty\n");
   return NULL;
 }
 else
 {
  while(temp->right!=NULL)
    temp=temp->right;
  return(temp->info);
 }
}

void main()
{
  node *s;
  int i,n;
  char ch;
  clrscr();
  do
  {
    printf(" 1->insertion \n 2->smallest ele\n 3->largest ele\n 4->exit\n");
    scanf("%d",&n);
    switch(n)
    {
     case 1: create(&s);
		do
		{
			printf("insert data : ");
			scanf("%d",&i);
			insert(&s,i);
			printf("again : ");
			fflush(stdin);
			scanf("%c",&ch);
		}
		while(ch=='y');
	     break;
     case 2: i = small(&s);
	     printf("smallest ele : %d \n",i);
	     break;
     case 3: i = large(&s);
	     printf("largest ele : %d \n",i);
	     break;
     case 4: exit();
	     break;
  }
 }
 while(n!=4);
 getch();
}


⌨️ 快捷键说明

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