首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >尝试编写带指针数组和冒泡排序的数据排序程序请协助

尝试编写带指针数组和冒泡排序的数据排序程序请协助
EN

Stack Overflow用户
提问于 2013-10-06 11:10:48
回答 1查看 1.4K关注 0票数 0

我不确定下一步该做什么,因为这些错误对我来说没有任何意义,也许我做错了什么,别人可以看到。这有所有正确的结构,只是我有错误的语法。任何帮助都是非常感谢的。

这是我的代码,这是我得到的结果,当我尝试编译时,我得到了这些错误:

代码语言:javascript
运行
复制
gcc Pointers.c

Pointers.c:14: error: expected ‘)’ before ‘array’
Pointers.c:32: error: expected ‘)’ before ‘array’
Pointers.c:44: error: expected ‘)’ before ‘array’
Pointers.c:56: error: expected ‘)’ before ‘array’
Pointers.c:78: error: expected ‘)’ before ‘pointer’
Pointers.c: In function ‘main’:
Pointers.c:102: error: ‘array’ undeclared (first use in this function)
Pointers.c:102: error: (Each undeclared identifier is reported only once
Pointers.c:102: error: for each function it appears in.)
Pointers.c:104: error: ‘pointer’ undeclared (first use in this function)

这是分配页面:

http://www.cs.miami.edu/~wuchtys/CSC322-13F/Assessment/LT5.html

代码语言:javascript
运行
复制
#include <stdio.h>
#include <stdlib.h>

#define SIZE_OF_ARRAY 5

//=============================================================================

    int *IntegerPtr;
    int  ArrayInt[SIZE_OF_ARRAY]; 
    int *ArrayPtr[SIZE_OF_ARRAY];

//----------------------------------------------------------------------------- 
/* Initializes the elements of an array of five integers to random integers 
 Initializes the elements of an array of five pointers to integers to point to the corresponding elements of the array of integers. */

void ArrayInitialize(ArrayInt array,ArrayPtr pointer){

  int i;
  srand(getpid());

  for (i =0, int < SIZE_OF_ARRAY; i++){

    array[i] = (int)rand()

  for (i =0, int < SIZE_OF_ARRAY; i++){

        pointer[i] = &array[i];
                                      }
                      }
    }

//-----------------------------------------------------------------------------
/*Have a function that prints an array of five integers*/

void ArrayPrint(ArrayInt array){
 int i;

   for (i =0, int < SIZE_OF_ARRAY; i++){
    printf("%d : %10d \n",i,array[i]);

 }
printf("\n");
}

//-----------------------------------------------------------------------------
/*Have a function that prints the integers pointed to by an array of five pointers to                                        integers.*/

void ArrayPointerPrint(ArrayInt array){
 int i;

   for (i =0, int < SIZE_OF_ARRAY; i++){
    printf("%d : %10d \n",i,pointer[i]);

 }
printf("\n");
}

//-----------------------------------------------------------------------------
/*Have a function that uses a bubble-sort to sort an array of five integers, in ascending order of the integers. */

void ArrayBubbleSort(ArrayInt array){

  int i;
  int j;
  int temp;

  for( i = (SIZE_OF_ARRAY - 1); i >= 0; i-- )
  {
    for( j = 1; j <= i; j++ )
    {
      if( *(array+(j-1)) > *(array+j))
      {
         temp = *array+(j-1));
        *array+(j-1)) = array+(j));
        *array+(j) = temp;
      }
    }
  }
}

//-----------------------------------------------------------------------------
/*Have a function that uses a bubble-sort to sort an array of five pointers to integers */
 void PointerBubbleSort(ArrayPtr pointer){

  int i;
  int j;
  int temp;

  for( i = (SIZE_OF_ARRAY - 1); i >= 0; i-- )
  {
    for( j = 1; j <= i; j++ )
    {
      if( *(pointer+(j-1)) > *(pointer+j))
      {
        temp = *pointer+(j-1));
        *pointer+(j-1)) = pointer+(j));
        *pointer+(j) = temp;
      }
    }
  }
}

//----------------------------------------------------------------------------- 

 int main(void) {

    array[SIZE_OF_ARRAY]; 

    pointer[SIZE_OF_ARRAY];

    ArrayInitialize(array,pointer);

    ArrayPrint(array);

    PointerBubbleSort(pointer);

    ArrayPointerPrint(pointer);

    ArrayBubbleSort(array);

    ArrayPrint(array);

    ArrayPointerPrint(pointer);

    return(EXIT_SUCCESS);

  }
EN

回答 1

Stack Overflow用户

发布于 2013-10-06 11:14:28

以下是变量:

代码语言:javascript
运行
复制
int *IntegerPtr;
int  ArrayInt[SIZE_OF_ARRAY]; 
int *ArrayPtr[SIZE_OF_ARRAY];

您的代码就像使用typedefs一样使用它们。

也许不是这样

代码语言:javascript
运行
复制
void ArrayInitialize(ArrayInt array,ArrayPtr pointer){

您想要使用

代码语言:javascript
运行
复制
void ArrayInitialize(int *array,int *pointer){

在您的所有代码中,尝试用int *替换ArrayIntArrayPointer,我认为它会被编译。

然后改变

代码语言:javascript
运行
复制
array[SIZE_OF_ARRAY]; 
pointer[SIZE_OF_ARRAY];

代码语言:javascript
运行
复制
int array[SIZE_OF_ARRAY]; 
int pointer[SIZE_OF_ARRAY];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19205018

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档