In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use C language recursive train scheduling algorithm, the text is very detailed, has a certain reference value, interested friends must read!
1. Code
The title is as follows:
2.8 Four trains numbered 1, 2, 3 and 4 pass through a stack of train dispatching stations. What are the possible dispatching results? If there are n trains passing through the dispatching station, please design an algorithm to output all possible dispatching results.
The idea of algorithm is to use stack + recursion, and the difficulty of algorithm lies in this. First the code:
#include #define MAX 100typedef struct s{ char a[MAX]; int top;}Stack;/* Define stack data *//* Define some global variables */Stack S;/* Define global stack */char d[MAX],seq[MAX];/*d[MAX] is used to store the original stack sequence, seq[MAX] is used to store the output sequence */int len;/* Defines the number of elements that will pass through the stack */ int count=0;/* is used to count the number of output sequences */void initStack(Stack *S) /* initializes the empty stack */{ S->top=-1;}void push(Stack *S,char x) /* push */{ if(S->top>=MAX) return; S->top++; S->a[S->top]=x;}char pop(Stack *S) /* pop */{ if (S->top==-1) { printf("ERROR, POP Empty Stack"); return -1; } S->top--; return S->a[S->top+1]; } int isEmpty(Stack *S)/* Determine whether the stack is empty */ { if (S->top==-1) return 1; return 0; } void outSeq(char *seq, int len)/* Output vertex sequence */ { int i; for(i=0; i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.