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

📄 text3.c

📁 集合了多种排序算法与数组操作功能。包括简单
💻 C
字号:
#include <stdio.h>
#include "text3.h"
void fileRead ( int *a , int *n )
{
	char sname[10];//源文件
    FILE *fp;
	printf("please input your source file name:\n");
	scanf("%s",sname);
	

	fp = fopen(sname,"r");
	if(fp==NULL)
	{	
		printf("file open error\n");
		exit(0);
	}//打开源文件

	for ( *n = 0 ; !feof(fp) ; (*n)++)
        fscanf( fp,"%d", &a[*n] );
	fclose (fp);
}

void fileWrite ( int *a , int n )
{
	FILE *fp;
	int i;
	char rname[10];//结果文件
	printf("please input your result file name:\n");
	scanf("%s",rname);
	
	fp=fopen(rname,"w");
	if(fp==NULL)
	{	
		printf("file open error\n");
		exit(0);
	}//打开结果文件
	
	for ( i=0 ; i < n  ; i++)
		fprintf( fp, "%3d", a[i] );
	fclose (fp);

}


void sort ()
{   
	char c;
	int a[80],n;
	printf ("which kind do you want to use:\n");
	printf ("bubbleSort:(b)\ninsertSort:(i)\nselectSort:(s)\nexit:(e)\n");
	c = getchar();
	c = getchar();
    printf ("you have chosen %c\n",c);
    switch ( c )
    {
    case 'b': fileRead( a , &n);
		bubbleSort ( a , n );
		fileWrite ( a , n );
		break;
	case 'i': fileRead( a , &n);insertSort ( a , 0 , n );fileWrite ( a , n );break;
	case 's': fileRead( a , &n);selectSort ( a , n );fileWrite ( a , n );break;
    case 'e': return;
	default:  printf ("wrong choice!!!\n ");return;

    }

}
void oper()
{
	char c;
	int a[80],n,j,t,m;
	printf ("which kind of operation do you want to use:\n");
	printf ("delete:(d)\ninsert:(i)\nfind:(f)\nexit:(e)\n");
	c = getchar();
	c = getchar();
    printf ("you have chosen %c\n",c);
    switch ( c )
    {
    case 'd':{
		fileRead( a , &n);
		printf ( "input the index you want to delete\n");
		scanf ("%d",&j);
		Delete ( a , &n , j);
		fileWrite ( a , n );
		break;
			 }
	case 'i': {
		fileRead( a , &n);
		printf ( "input the index you want to insert\n");
		scanf("%d",&j);
        printf ( "input the number you want to insert\n");
		scanf("%d",&t);

		insert (a, &n , j , t); 
		fileWrite ( a , n );
		break;
			 }
	case 'f':{
		fileRead( a , &n);
        printf ( "input the number you want to find\n");
		scanf("%d",&t);

		m = bidivideFind (a,0,n-1,t);
		
 		fileWrite ( a , n );
		if ( m != n )
			printf ( "the number %d is in the %d place\n ", t, m );
		else
			printf ( "there is no such number\n");
		break;
			 }
    case 'e': return;
	default:  printf ("wrong choice!!!\n ");return;

    }

}
void main()
{
    char c;
	while (1)
	{	
		printf ("what do you want to do ?\n");
		printf ("sort a number group;(s)\noperations to a sorted number;(o)\nexit;(e)\n");
		;
		c = getchar();
        printf ("you have chosen %c\n",c);
		switch ( c )
		{
			case 's': sort ();break;
			case 'o': oper ();break;
			case 'e': getchar();exit (0);
			default:printf ("wrong choice!!!\n ");
		}

	}
}

⌨️ 快捷键说明

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