数据结构管理员审核用户注册用c语言实现
时间: 2024-06-05 17:04:49 浏览: 16
数据结构管理员审核用户注册可以使用C语言实现。一种常见的实现方式是使用链表数据结构来存储注册用户的信息。当新用户注册时,管理员将其信息存储在链表中。当管理员需要审核用户时,可以遍历链表查看每个用户的信息,以便决定是否批准其注册申请。
以下是一个简单的示例代码,用于实现用户注册和审核:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义用户信息结构体
struct UserInfo {
char name[20];
char email[50];
char password[20];
int is_approved;
struct UserInfo *next;
};
// 定义链表头指针
struct UserInfo *head = NULL;
// 添加新用户
void add_user(char *name, char *email, char *password) {
// 创建新节点
struct UserInfo *new_user = (struct UserInfo*) malloc(sizeof(struct UserInfo));
strcpy(new_user->name, name);
strcpy(new_user->email, email);
strcpy(new_user->password, password);
new_user->is_approved = 0; // 默认未审核
new_user->next = NULL;
// 将新节点插入链表尾部
if (head == NULL) {
head = new_user;
} else {
struct UserInfo *cur = head;
while (cur->next != NULL) {
cur = cur->next;
}
cur->next = new_user;
}
}
// 审核用户
void approve_user(char *email) {
struct UserInfo *cur = head;
while (cur != NULL) {
if (strcmp(cur->email, email) == 0) {
cur->is_approved = 1;
printf("User %s is approved.\n", cur->name);
return;
}
cur = cur->next;
}
printf("User not found.\n");
}
// 打印所有用户
void print_users() {
struct UserInfo *cur = head;
while (cur != NULL) {
printf("%s (%s) - %s\n", cur->name, cur->email, cur->is_approved ? "Approved" : "Not approved");
cur = cur->next;
}
}
int main() {
// 添加一些测试用户
add_user("Alice", "alice@example.com", "123456");
add_user("Bob", "bob@example.com", "abcdef");
// 审核一个用户
approve_user("bob@example.com");
// 打印所有用户
print_users();
return 0;
}
```