#include<stdio.h>
#include<stdlib.h>
#include"001.h"
#pragma once
void SeqListInit(SL2* ps)//初始化
{
ps->a = NULL;
ps->size = ps->capacity = 0;
}
void SeqListPushBack(SL2* ps, SLDateType x)//尾插一个数据
{
if (ps->size=ps->capacity)
{
int newcapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;
SLDateType* tmp = (SLDateType*)realloc(ps->a,newcapacity*sizeof(SLDateType));
if (tmp=NULL)
{
printf("realloc fail\n");
exit(-1);
}
ps->a = tmp;
ps->capacity = newcapacity;
}
ps->a[ps->size] = x;
ps->size++;
}
void SeqListPrint(SL2* ps)
{
for (int i = 0; i < ps->size; i++)
{
printf("%d\n", ps->a[i]);
}
}
void testseqlist()
{
SL2 s1;
SeqListInit(&s1);
SeqListPushBack(&s1, 1);
SeqListPushBack(&s1, 2);
SeqListPushBack(&s1, 3);
SeqListPushBack(&s1, 4);
SeqListPrint(&s1);
}
int main()
{
testseqlist();
return 0;
}
在这出现了问题
#pragma once
#define N 100
#include<stdio.h>
#include<stdlib.h>
typedef int SLDateType;
//静态顺序表
typedef struct SeqList1
{
SLDateType a[N];
int size;//表示存储了多少个数据
}SL1;
void SeqListPrint(SL1* ps);//打印
void SeqListInit(SL1* ps);
void SeqListPushBack(SL1*ps,SLDateType x);//尾插
void SeqListPushFront(SL1* PS, SLDateType);//头插
void SeqListPopBack(SL1* PS);//尾删
void SeqListPopFront(SL1* PS);//头删
//动态顺序表
typedef struct seqlist2
{
SLDateType* a;
int size;//表示存储了多少个数据
int capacity;//数组实际能存的数据空间有多大
}SL2;
不知道问题出在哪
两处问题,在.cpp文件里:
第13行: if (ps->size=ps->capacity) 应修改为:if (ps->size == ps->capacity)
第17行:if (tmp=NULL) 应修改为:if (tmp == NULL)
#include<stdio.h>
#include<stdlib.h>
#include"001.h"
#pragma once
void SeqListInit(SL2* ps)//初始化
{
ps->a = NULL;
ps->size = ps->capacity = 0;
}
void SeqListPushBack(SL2* ps, SLDateType x)//尾插一个数据
{
if (ps->size == ps->capacity) //if (ps->size = ps->capacity) 修改
{
int newcapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;
SLDateType* tmp = (SLDateType*)realloc(ps->a, newcapacity * sizeof(SLDateType));
if (tmp == NULL) //if (tmp = NULL) 修改
{
printf("realloc fail\n");
exit(-1);
}
ps->a = tmp;
ps->capacity = newcapacity;
}
ps->a[ps->size] = x;
ps->size++;
}
void SeqListPrint(SL2* ps)
{
for (int i = 0; i < ps->size; i++)
{
printf("%d\n", ps->a[i]);
}
}
void testseqlist()
{
SL2 s1;
SeqListInit(&s1);
SeqListPushBack(&s1, 1);
SeqListPushBack(&s1, 2);
SeqListPushBack(&s1, 3);
SeqListPushBack(&s1, 4);
SeqListPrint(&s1);
}
int main()
{
testseqlist();
return 0;
}
不知道你这个问题是否已经解决, 如果还没有解决的话:void outdegree(MGraph G)
{
for(int i = 0; i < G.vexnum; i++)
{
int c = 0;
for(int j = 0; j < G.vexnum; j++)
if(G.arcs[i][j] == 1)
c++;
printf("%c:%d\n",G.vexs[i],c);
}
}
我很高兴能帮助您解决IT问题。但在您的提问中找不到具体的问题描述,请提供具体的问题,以便我为您提供解决方案。