編譯環境:visual studio2019
一開始說我溢位,然后我就把堆疊擴大,結果一直提示正在重寫
還有就是顯示這個錯誤
源代碼:
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define INF 32767
#define MAXSIZE 1000
#define N 5
typedef int elemtype;
int adjacency_array[N][N] = { {0, 6, INF, 2, INF},
{INF, 0, 10, INF, 3},
{INF, INF, 0, INF, 8},
{INF, INF, 1, 0, INF},
{INF, INF, INF, 12, 0} };
int visited_deep[N * N] = { 0 };
typedef struct node { // 定義一個鄰接表結點資料型別
int id; // 結點編號
struct node* pnext; // 指向下一個結點的指標
int weight; // 通向下一個結點的邊的權值
} Node;
typedef struct { // 定義一個圖的鄰接表資料型別
Node* headnode[MAXSIZE];
int vertex; // 頂點數
int edge; // 邊數
} Graph;
typedef struct {
int data[MAXSIZE];
int head;
int tail;
} Queue;
typedef struct {
//定義鄰接矩陣的資料型別
elemtype vex[MAXSIZE];
int arc[MAXSIZE][MAXSIZE];
int e, n;
}graph;
int locatevex(graph g, elemtype v)
{
int i;
for (i = 0;i < g.n;i++)if (g.vex[i] == v)return i;
return -1;
}
void creat_graph_adjacency_list(Graph* pgraph, int vertex, int edge);
void print_graph(Graph* pgraph);
void distory_graphy(Graph** ppgraph);
void deep_first_search(Graph* pgraph, int start);
void breadth_first_search(Graph* pgraph, int start);
void in_queue(Queue* q, int id);
void out_queue(Queue* q, int* temp);
main() {
Graph* pgraph = (Graph*)calloc(1, sizeof(Graph));
creat_graph_adjacency_list(pgraph, N, 7);
printf("該圖的鄰接矩陣為:\n");
graph(pgrah);
printf("該圖的鄰接表為:\n");
print_graph(pgraph);
printf("該圖的一個深度優先遍歷序列為:\n");
deep_first_search(pgraph, 0);
printf("\n該圖的一個廣度優先遍歷序列為:\n");
breadth_first_search(pgraph, 0);
distory_graphy(&pgraph);
return 0;
}
void create_graph_array(graph* G) {
int i, j, k, w;
for (i = 0;i < 12;i++) {
for (j = 0;j < 12;j++) {
G->arc[i][j] = INF;
}
}
}
void creat_graph_adjacency_list(Graph* pgraph, int vertex, int edge) { //創建圖的鄰接表
int i, j;
for (i = 0; i < vertex; i++) {
pgraph->headnode[i] = NULL;
}
for (i = 0; i < vertex; i++) {
for (j = vertex - 1; j >= 0; j--) {
if (adjacency_array[i][j] != 0 && adjacency_array[i][j] != INF) {
Node* pnew = (Node*)calloc(1, sizeof(Node));
pnew->id = j;
pnew->weight = adjacency_array[i][j];
pnew->pnext = pgraph->headnode[i]; // 頭插法創建單鏈表
pgraph->headnode[i] = pnew;
}
}
}
pgraph->vertex = vertex;
pgraph->edge = edge;
return;
}
void print_graph(Graph* pgraph) { // 列印鄰接表
int i;
Node* phead;
if (pgraph == NULL) {
printf("The graph is empty!\n");
}
else {
for (i = 0; i < pgraph->vertex; i++) {
phead = pgraph->headnode[i];
printf("%d ", i);
while (phead != NULL) {
printf("%d[%d] -> ", phead->id, phead->weight);
phead = phead->pnext;
}
printf("NULL\n");
}
}
free(phead);
phead = NULL;
return;
}
void distory_graphy(Graph** ppgraph) { // 銷毀鄰接表
int i;
Node* ppre, * pcur;
for (i = 0; i < (*ppgraph)->vertex; i++) {
ppre = (*ppgraph)->headnode[i];
if (ppre != NULL) {
pcur = ppre->pnext;
while (pcur != NULL) {
free(ppre);
ppre = pcur;
pcur = pcur->pnext;
}
free(ppre);
}
else {
free(ppre);
ppre = NULL;
}
}
free(*ppgraph);
*ppgraph = NULL;
return;
}
void deep_first_search(Graph* pgraph, int start) { // 深度優先遍歷
Node* p;
visited_deep[start] = 1;
printf("%d ", start);
p = pgraph->headnode[start];
while (p != NULL) {
if (visited_deep[p->id] == 0) {
deep_first_search(pgraph, p->id);
}
p = p->pnext;
}
return;
}
void breadth_first_search(Graph* pgraph, int start) { // 廣度優先遍歷
Queue* q = (Queue*)calloc(1, sizeof(Queue));
q->head = 0;
q->tail = 0;
int visited[N * N] = { 0 };
int temp;
Node* pcur;
printf("%d ", start);
visited[start] = 1;
in_queue(q, start);
while (q->tail != q->head) { // 環形佇列非空時
out_queue(q, &temp);
pcur = pgraph->headnode[temp];
while (pcur != NULL) { // 遍歷pcur的所有鄰接點
if (visited[pcur->id] == 0) {
printf("%d ", pcur->id);
visited[pcur->id] = 1;
in_queue(q, pcur->id);
}
pcur = pcur->pnext;
}
}
return;
}
void in_queue(Queue* q, int id) { // 入堆疊環形佇列
if ((q->tail + 1) % MAXSIZE == q->head) {
printf("The queue is full!\n");
}
else {
q->tail = (q->tail + 1) % MAXSIZE;
q->data[q->tail] = id;
}
return;
}
void out_queue(Queue* q, int* temp) {
if (q->tail == q->head) {
printf("The queue is empty!\n");
}
else {
q->head = (q->head + 1) % MAXSIZE;
*temp = q->data[q->head];
}
return;
}
警告與錯誤:
嚴重性 代碼 說明 專案 檔案 行 禁止顯示狀態
警告 D9025 正在重寫“/analyze-”(用“/analyze:stacksize4004020”) 圖 C:\Users\jyz_1\source\repos\圖\cl 1
嚴重性 代碼 說明 專案 檔案 行 禁止顯示狀態
錯誤 C1001 內部編譯器錯誤。 圖 C:\Users\jyz_1\source\repos\圖\源.c 1
uj5u.com熱心網友回復:
這種錯誤不是代碼引起的,是硬體、系統、VS安裝或專案配置問題。建議以同樣環境寫個helloworld來確認環境正確性。
uj5u.com熱心網友回復:
hello world倒是可以成功運行......那這種情況一般是哪里有問題呢?
uj5u.com熱心網友回復:
那我建議把你的代碼復制到正常的helloworld的專案的編輯界面覆寫那個短短的代碼,再編譯試試。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/241620.html
標籤:C語言
下一篇:請教一下字符分割
