In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.