小编use*_*923的帖子

如何使用指针执行冒泡排序

我已经使用Pointers为Bubble Sort编写了这段代码,但是我遇到了像LVALUE这样的错误.

这是我的代码.请修复此代码.我基本上在交换语法时遇到错误.请帮忙

#include<stdio.h>
#include<conio.h>
void sort(int *a,int n);
void main()
{
    int a[20];
    int n,i;
    clrscr();
    printf("Program for BUBBLE SORT\n");
    printf("Enter the Number of ELements you want in Array\n");
    scanf("%d",&n);
    printf("Enter the Elements in UNSOTED ARRAY\n");
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    printf("The Unsorted ARRAY is:\n");
    for(i=0;i<n;i++)
    {
        printf("%d\t",a[i]);
    }
    printf("\n");
    sort(&a,n);
    getch();
}
void sort(int *a,int n)
{
    int i,temp,j;
    for(i=1;i<n;i++)
    {
        for(j=0;j<n-i;j++)
        {
            if((*a+j)==(*a+j+1))
            {
                temp=*a+j;
                *a+j=*a+j+1;
                *a+j+1=temp;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c sorting bubble-sort

-4
推荐指数
1
解决办法
3万
查看次数

标签 统计

bubble-sort ×1

c ×1

sorting ×1