C++ 无法获取输出联合集

C++ 无法获取输出联合集,c++,c,C++,C,实际上,当我使用Xcode编译时,这是一个纯C程序。没有错误。但是仍然不能得到输出,除非你强制停止,否则过程不会停止 #include <stdio.h> #include <stdlib.h> #include <time.h> int LocateElem(int *p1,int e,int leng1); void Display(int max, int array[]); int GetElem(int * p, int pass); int Uni

实际上,当我使用Xcode编译时,这是一个纯C程序。没有错误。但是仍然不能得到输出,除非你强制停止,否则过程不会停止

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int LocateElem(int *p1,int e,int leng1);
void Display(int max, int array[]);
int GetElem(int * p, int pass);
int Union(int *p1,int *p2, int leng1, int leng2);
int ListInsert(int **p, int e, int lengA);
int* GetData(int* pArray, int Array_size);
void Show(int *p, int leng);

void InitList_Sq(int  *L);
int *p_A,*p_B;
int m,n;

int main()
{
    clock_t begin, end;
    double  cost;
    begin = clock();


    printf("How many elements of A u want:");
    scanf("%d",&m);
    if (m<0) {
        printf("Error!");
        return 0;
    }
    printf("How many elements of B u want:");
    scanf("%d",&n);
    if (n<0) {
        printf("Error!");
        return 0;
    }

    p_A=(int *)malloc(m*sizeof(int));
    p_B=(int *)malloc(n*sizeof(int));
    if (p_A==NULL) {
        printf("Error allocating memory!\n"); //print an error message
        return 0; //return with failure
    }
    if (p_B==NULL) {
        printf("Error allocating memory!\n"); //print an error message
        return 0; //return with failure
    }

    int *pLast_A, * pLast_B;
    printf("Array A is :\n");
    pLast_A=GetData(p_A, m);
    printf("\nArray B is :\n");
    pLast_B=GetData(p_B, n);

    int newLeng;
    newLeng=Union(p_A,p_B,m,n);

    printf("\nThe Union set is :\n");
    Show(p_A, newLeng);

    free(p_A);
    free(p_B);
    end = clock();
    cost = (double)(end - begin) / CLOCKS_PER_SEC;
    printf("\n%lf seconds", cost);
    return 1;


}


int* GetData(int* pArray, int Array_size){
    int* pFill= pArray;
    int count;
    srand((unsigned) time(NULL));
    for ( count=0; count< Array_size; count++) {
        *(pFill+count)=rand()%1000;
        printf("%d\t", * (pFill+count));
    }
    return pFill+count-1;
}


int Union(int *p1,int *p2, int leng1, int leng2){
    for (int count=0; count<leng2; count++) {
        int e=GetElem(p2, count);
        while(LocateElem(p1, e, leng1)==0){
            leng1=ListInsert(&p1, e, leng1);
        }
    }
    return leng1;
}

int GetElem(int *p, int pass){
    return  *(p+pass);
}

int LocateElem(int *p1,int e,int leng1){
    for (int count=0; count<leng1; count++)
        if (e==*(p1+count))
            return 1;
        else
            return 0;
}

int ListInsert(int **p, int e, int lengA){
    lengA+=1;
    int* temp;
    temp=(int*)realloc(*p, lengA*sizeof(int));
    if (temp==NULL) {
        printf("Error allocating memory!\n"); //print an error message
        free(temp);
        return 0; //return with failure
    }
    else{
        *p=temp;
        *(*p+lengA-1)=e;

    }
    return lengA;

}

void Show(int *p, int leng){
    for (int count=0; count<leng; count++) {
        printf("%d\t", *(p+leng));
    }
}
#包括
#包括
#包括
内部位置元素(内部*p1、内部e、内部长度1);
无效显示(整数最大值,整数数组[]);
int GetElem(int*p,int pass);
int并集(int*p1,int*p2,int leng1,int leng2);
int ListInsert(int**p、int e、int lengA);
int*GetData(int*pArray,int数组大小);
无效显示(整数*整数,整数长度);
无效初始列表_Sq(int*L);
int*p_A,*p_B;
int m,n;
int main()
{
时钟开始,结束;
双重成本;
开始=时钟();
printf(“u需要多少元素:”);
scanf(“%d”、&m);
如果(m

while(LocateElem(p1, e, leng1)==0)
始终返回true,而循环从不退出并继续运行该行:

leng1=ListInsert(&p1, e, leng1);
这样就可以永远分配内存

int ListInsert(int **p, int e, int lengA){
    lengA+=1;
    int* temp;
    temp=(int*)realloc(*p, lengA*sizeof(int));
    .
    .
    .

没有人会在这里调试您的代码