C语言中的单链表-向后
我试图创造这个,但这对我来说很难。有人能帮我解释一下吗? 显示菜单 要求用户选择输入 如果用户选择1,则: 检查是否有任何数字可以用5除或否->如果是,显示所有可以用5除的数字 如果用户选择2,则: 检查是否有奇数->如果有,将所有奇数相加 如果用户选择3,则: 显示最大的数字&显示它 如果用户选择4,则: 显示最小的数字&显示它C语言中的单链表-向后,c,C,我试图创造这个,但这对我来说很难。有人能帮我解释一下吗? 显示菜单 要求用户选择输入 如果用户选择1,则: 检查是否有任何数字可以用5除或否->如果是,显示所有可以用5除的数字 如果用户选择2,则: 检查是否有奇数->如果有,将所有奇数相加 如果用户选择3,则: 显示最大的数字&显示它 如果用户选择4,则: 显示最小的数字&显示它 #include <stdio.h> #include <stdlib.h> typedef struct node{ int nu
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int num;
struct node* link;
}NODE;
int main (){
//assumption : total number = 5
//1. create 5 node
for (int i=1; i<=5;i++){
createNode();
}
//repeat step 2 - 4 if choose !=5
//2. show menu
//3. ask user to choose input
//4. if user choose 1, then :
// check if there any number can divide with 5 or no --> if yes, show all the number that can divide with 5
// if user choose 2, then :
// check if there any number are odd --> if yes, sum all odd number
// if user choose 3, then :
// show the highest number & show it
// if user choose 4, then :
// show the smallest number & show it
//4a. choose 1
if (choose==1){
for (..............){
if(newNode->num % 5 == 0 ){
printf (.............); // show numbers
}
}
}
//4c. choose 3
else if (choose==3){
for (int i=1;i<=5;i++){
}
}
// 5, 3, 10, 4, 1
// assumption the highest = 10
newNode= head;
assumption = newNode->bil;
for (.........){
if (newNode->num > assumption ){
assumption = ....... ;
}
newNode = newNode->link;
}
printf (.........................)
}
之后,您将为此列表构建基本函数 您可以使用每个函数执行任务:
int SlistForeach(node_t from, node_t to , action_func_t
action_func, void *param)
{
int stat = 1;
node_t index = from;
assert(NULL != to);
assert(NULL != from);
while(index != to)
{
stat = action_func(&(index->data), param);
if(0 == stat)
{
return (stat);
}
index = index->next;
}
return(stat);
}
你必须表现出一些努力。做你的家庭作业。这不是一个程序,也不是一个问题。这对我来说很难不描述一个工程问题。除了程序的所有缺失部分和语法错误之外,我认为没有理由使用链表来解决指定的功能。我也看不到任何与你的问题标题“向后”匹配的内容。我认为它应该是索引!=to->next'因为您确实希望在支票中包含to'。这取决于实现