Singly Linked List-在C中向后

  • 本文关键字:Linked List- Singly c
  • 更新时间 :
  • 英文 :


我试图创建这个,但对我来说很难。有人能帮我解释一下吗?显示菜单要求用户选择输入如果用户选择1,则:检查是否有任何数字可以除以5或者没有-->如果是,显示所有可以除以5的数字如果用户选择2,则:检查是否有奇数-->如果是,对所有奇数求和如果用户选择3,则:显示最高数字&展示它如果用户选择4,则:显示最小的数字&显示

#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);
}

最新更新