This commit is contained in:
xusun000
2021-12-01 13:11:46 +08:00
2 changed files with 86 additions and 1 deletions

View File

@@ -1,4 +1,45 @@
#include <stdio.h>
#include <stdlib.h>
#define MAXV 5
typedef struct {
int numVertices, numEdges;
char VerticesList[MAXV];
int Edge[MAXV][MAXV];
}MGraph;
int IsExistEL(MGraph G) {
int oddCount = 0;
for (int i = 0;i < G.numVertices;i++) {
int tmpOdd = 0;
for (int j = 0;j < G.numVertices;j++) {//遍历每一行,将个数统计出来
tmpOdd += G.Edge[i][j];
}
if (tmpOdd % 2 == 1) {//如果个数是奇数就将oddCount+1
oddCount++;
if (oddCount > 2) {
return 0;
}
}
}
if (oddCount == 0 || oddCount == 2)return 1;
else return 0;
}
void setG(MGraph* g, int a[]) {
for (int i = 0;i < MAXV * MAXV;i++) {
g->Edge[i / 5][i % 5] = a[i];
}
}
int main() {
printf("hello");
MGraph G;
G.numVertices = 5;
int a[] = {
1,1,0,0,1,//
1,0,1,0,1,//
0,1,0,1,1,//
0,0,1,0,1,//
0,0,0,1,0,//
};
setG(&G, a);
int i = IsExistEL(G);
printf("%d", i);
return 0;
}

44
code_link_2015.cpp Normal file
View File

@@ -0,0 +1,44 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node {
int data;
struct node* link;
}NODE;
void create(NODE* p, int a[], int pos, int length) {
if (pos < length) {
p->data = a[pos];
p->link = (NODE*)malloc(sizeof(NODE));
p->link->data = INT_MIN;//用INT_MIN作为结束标志
create(p->link, a, pos + 1, length);
}
}
void deleteNode(NODE* p, int n, int length) {
int* a = (int*)malloc(sizeof(int) * (n + 1));
memset(a, 0, sizeof(int) * (n + 1));
NODE* pHead = p, * q;
a[p->data > 0 ? p->data : -p->data] = 1;
while (p->link != NULL && p->link->data != INT_MIN) {
int t = (p->link->data) > 0 ? p->link->data : -p->link->data;
if (a[t] == 1) {
q = p->link;
p->link = q->link;
free(q);
}
else {
a[t] = 1;
p = p->link;
}
}
}
int main() {
int a[] = { -5,5,9,17,5,5,5,-3,2,5 };
NODE pStart;
create(&pStart, a, 0, 10);
deleteNode(&pStart, 100, 10);
return 0;
}