数据结构学习笔记(一)不断更新

这里将学过的数据结构做一个整理

//
//  main.c
//  数据结构
//
//  Created by 杜甲 on 14-8-17.
//  Copyright (c) 2014年 杜甲. All rights reserved.
//

#include <stdio.h>
//一维数组的倒置


#define M 20
void fun(int *x,int n)
{
    int *p,m=n/2,*i,*j;
    i=x;
    j=x+n-1;
    p=x+m;
    for(;i<p;i++,j--)
    {
        int t=*i;
        *i=*j;
        *j=t;
    }
}

int main(int argc, const char * argv[])
{
    int i,a[M],n;
    printf("\nEnter n:\n");
    scanf("%d",&n);
    printf("The original array:\n");
    for(i=0;i<n;i++)
        scanf("%d",a+i);
    fun(a,i);
    printf("\nThe array inverted:\n");
    for(i=0;i<n;i++)
        printf("%d  ",*(a+i));
    
    
    
    return 0;
}


//
//  main.c
//  数据结构
//
//  Created by 杜甲 on 14-8-17.
//  Copyright (c) 2014年 杜甲. All rights reserved.
//

#include <stdio.h>
//一维数组应用   主要功能查询工资,修改工资

int main(int argc, const char * argv[])
{
    int  Employee[10]={27000,32000,32500,27500,30000,29000,31000,32500,30000,26000};
	int  Index;
	int  NewSalary;
	int  Selection;
	while(1)
	{
		printf("===================================================\n");
		printf("=Simple Employee Salary Management System         =\n");
		printf("=1.Display employee salary                        =\n");
		printf("=2.Modify employee salary                         =\n");
		printf("=3.Quit                                           =\n");
		printf("Please input your choose:");
		scanf("%d",&Selection);
		if(Selection==1||Selection==2)
		{
			printf("**Please input the employee number:");
			scanf("%d",&Index);
			if(Index<10)
			{
                printf("**Employee Number is %d.",Index);
                printf("The Salary is %d\n",Employee[Index]);
			}
			else
			{
                printf("##The error employee number!\n");
                return 1;
                
			}
		}
		switch(Selection)
		{
		    case  1:
                break;
            case   2:
                printf("**Please input new salary:");
                scanf("%d",&NewSalary);
                Employee[Index]=NewSalary;
                break;
            case    3:
                return 0;
                break;
        }
        printf("\n");
    }
    
    return 0;
}


你可能感兴趣的:(数据结构,c)