int SearchList(struct MyList *L, char variable, char temp_find) { struct MyList *temp = L->next; printf("查找中\n"); while (temp != NULL) { if (!strcmp(variable, "编号")) if (!strcmp(temp->thing.num, temp_find)) { printf(" 班费收支编号为: %s\n", temp->thing.num); printf(" 收入和还是支出: %s\n", temp->thing.into); printf(" 经办人是: %s\n", temp->thing.name); printf(" 收费原因为: %s\n", temp->thing.cause); printf(" 收费金额为: %s\n", temp->thing.money); printf(" 收费的总人数为: %s\n", temp->thing.people); printf(" 收费的日期为: %s\n", temp->thing.time); printf("\n"); }
时间: 2024-04-25 10:27:01 浏览: 7
这段代码是一个函数,函数名为 SearchList,作用是在链表 L 中查找符合条件的节点。函数有三个参数:一个指向链表的指针 L,一个字符变量 variable,一个字符变量 temp_find。其中 variable 用于指定查找的条件是编号,temp_find 用于存储需要查找的编号。
该函数会在链表中遍历每一个节点,如果节点的编号与 temp_find 相等,则输出该节点的相关信息,包括编号、收入和还是支出、经办人、收费原因、收费金额、收费的总人数、收费的日期等。
相关问题
struct MyList { fee thing; struct MyList *next; }; int InitList(struct MyList *L); int InsertList(struct MyList *L, fee e); void FinderList(struct MyList *L); int SearchList(struct MyList *L, char variable, char temp_find); int ReplacedList(struct MyList *L, int i, char* num, char* into, char* name, char* cause, char* money, char* people, char* time); int DeleteList(struct MyList *L, int i); int ClearList(struct MyList *L);
这段代码定义了一个链表结构体MyList,包含了两个成员:thing和next。其中thing是一个结构体变量,用来存储班费信息,next是一个指向下一个链表结构体的指针。除此之外,代码中还定义了若干个函数,包括:
1. InitList:初始化链表,将链表中的所有元素清空。
2. InsertList:在链表中插入一个元素。
3. FinderList:查找链表中的元素。
4. SearchList:根据班费信息的某个字段,在链表中查找符合条件的元素。
5. ReplacedList:替换链表中的某个元素。
6. DeleteList:删除链表中的某个元素。
7. ClearList:清空整个链表。
这些函数实现了链表的基本操作,可以用来对班费信息进行增删改查等操作。需要注意的是,代码中的函数参数有些简略,具体实现需要参考函数体中的代码。
void push_tail(struct LinkList* list, struct Node* temp) { temp->pro = list->head; temp->next = list->tail; list->tail->pro = temp; list->head->next = temp; list->head = temp; }优化一下这个代码,使用双向链表的头插法
void push_head(struct LinkList* list, struct Node* temp) {
temp->next = list->head->next;
temp->pro = list->head;
list->head->next->pro = temp;
list->head->next = temp;
list->tail = (list->tail == list->head) ? temp : list->tail;
}
这是使用双向链表头插法的代码。需要注意的是,当链表为空时,头尾节点都需要指向新插入的节点。因此,需要判断一下链表是否为空。