int EvaluateExpression() { char ch; type e,theta,a,b; SqStack OPTR,OPND; //OPTR为运算符栈,OPND为运算数栈 StackInit(&OPTR); StackInit(&OPND); Push(&OPTR,'#'); ch=getchar(); while(ch!='#' || GetTop(&OPTR)!='#') { if(!In(ch)) { Push(&OPND,ch); ch=getchar(); } else { switch(Precede(GetTop(&OPTR),ch)) { case '<':Push(&OPTR,ch); ch=getchar(); break; case '=':Pop(&OPTR,&e); ch=getchar(); break; case '>':Pop(&OPTR,&theta);Pop(&OPND,&b);Pop(&OPND,&a); Push(&OPND,Operate(a,theta,b)); break; } } } return GetTop(&OPND); }
void DFS(int i) { for (int m = 0; m < n; m++) { visited[m] = 0; } int counter = 0; StackInit(); visited[i] = 1; Stackpush(i); fprintf(fout,"%d ->", i); counter++; i = getTop(); while (top != 0) { for (int w = 0; w < n; w++) { if ((!visited[w]) && adj_mat[i][w]) { Stackpush(w); visited[w] = 1; counter++; fprintf(fout,"%d ", w); if (counter<n) fprintf(fout," -> "); i = getTop(); w = 0; } } Stackpop(); i = getTop(); } }
void DFSShowGraphVertex(ALGraphDFS*graph,int startV){ Stack stack; int visitV=startV; int nextV; StackInit(&stack); VisitVertex(graph,visitV); SAPush(&stack,visitV); while(LDFirst(&(graph->list[visitV]),&nextV)==TRUE){ int visitFlag=FALSE; if(VisitVertex(graph,nextV)==TRUE){ SAPush(&stack,visitV); visitV=nextV; visitFlag=TRUE; } else{ while(LDNext(&(graph->list[visitV]),&nextV)==TRUE){ if(VisitVertex(graph,nextV)==TRUE){ SAPush(&stack,visitV); visitV=nextV; visitFlag=TRUE; break; } } } if(visitFlag==FALSE){ if(SABIsEmpty(&stack)==TRUE) break; else visitV=SABPop(&stack); } } memset(graph->visit,0,sizeof(int)*graph->numV); }
//后序遍历 void PostOrderUnrec(Bitree t) { SqStack s; stacknode x; StackInit(s); p=t; do { while (p!=null) //遍历左子树 { x.ptr = p; x.tag = L; //标记为左子树 push(s,x); p=p->lchild; } while (!StackEmpty(s) &&s.Elem[s.top].tag==R) { x = pop(s); p = x.ptr; visite(p->data); //tag为R,表示右子树访问完毕,故访问根结点 } if (!StackEmpty(s)) { s.Elem[s.top].tag =R; //遍历右子树 p=s.Elem[s.top].ptr->rchild; } }while (!StackEmpty(s)); }//PostOrderUnrec
void qsort_1 (int *arr, int size) { stackT stack; stackElementT element, e; int k; StackInit (&stack, size); element.left = 0; element.right = size - 1; StackPush(&stack, element); while (!StackIsEmpty (&stack)) { element = StackPop (&stack); while (element.left < element.right) { if (element.right - element.left < SWITCH_THRESH) { insertsort(&arr[element.left], element.right - element.left + 1); element.left = element.right; } else { k = partition(arr, element.left, element.right); e.left = element.left; e.right = k; StackPush(&stack, e); element.left = k+1; } } } StackDestroy (&stack); return; }
// Depth First Search void DFS(Graph* mygraph) { // initialize arrays // inStack array keeps information about nodes whether they are in stack int index[mygraph->MaxSize]; int lowlink[mygraph->MaxSize]; int inStack[mygraph->MaxSize]; stackT stack; // initialize stack StackInit(&stack, mygraph->MaxSize); // for each node in the graph for (int i = 1; i < mygraph->MaxSize; i++) { index[i] = -1; lowlink[i] = -1; inStack[i] = 0; // 0 - false } // for each node if it it not visited yet // send note to strongly connected components function for (int i = 1; i < mygraph->MaxSize; i++) { if (index[i] == -1) { SCC(mygraph, i, index, lowlink, stack, inStack); } } }
int main() { int arr[] = { 1, 2, 3, 4, 5, 6, 7 }; int i = 0, *top = 0; Stack stack; StackInit(&stack, sizeof(int)); while (i < sizeof(arr) / sizeof(int)) { StackPush(&stack, &arr[i]); ++i; } top = StackTop(&stack); printf("The top of the stack element is %d\n", *top); top = StackPop(&stack); printf("Pop element %d\n", *top); top = StackTop(&stack); printf("The top of the stack element is %d\n", *top); printf("The stack size is %d\n", StackSize(&stack)); StackClear(&stack); if (StackEmpty(&stack)) { printf("Stack is empty.\n"); } else { printf("Stack is not empty.\n"); } StackDestory(&stack); return 0; }
//查找 int GraphListDepthFind(AdjList *graph, int v, int t) { int visited [MAX_VERTEX_NUM] = {0}; int i = 0; ArcNode *p; StackNode *stack; StackDataElem e; stack = (StackNode *)malloc(sizeof(StackNode)); StackInit(stack); e.a = v; StackPush(stack, e); while(StackEmpty(stack)){ StackPop(stack, &e); i = e.a; if(!visited[i]){ printf("%d", i); visited[i] = 1; } if(i == t){ return 0; } p = graph->vertex[i].fristarc; while(p != NULL){ if(!visited[p->adjvex]){ e.a = p->adjvex; StackPush(stack, e); } p = p->nextarc; } } return 0; }
int main(int argc, char *argv[]) { pthread_t threads[6]; pthread_attr_t attr; int rc; int i; srand(time(NULL)); Stack * stack = (Stack *)malloc(sizeof(Stack)); StackInit(stack, 4); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); for(i=0; i<5; i++) { pthread_create(&threads[i], NULL, Inserisci, (void *)stack); } pthread_create(&threads[5], NULL, Preleva, (void *)stack); for(i=0; i<6; i++) { pthread_join(threads[i], NULL); } StackRemove(stack); }
int Alg(int cows[STACK_SIZE], int numOfCow){ int i,j; int count[STACK_SIZE]={0}; int tempCount=0, sum=0; int idx; Stack stack; StackInit(&stack); Push(&stack,numOfCow-1); count[numOfCow-1] = 0; for (i=numOfCow-2; i>=0; i--){ while((!IsEmpty(&stack))&&(cows[i] > cows[Seek(&stack)])){ idx = Pop(&stack); count[i] += (count[idx]+1); sum += (count[idx]+1); } Push(&stack,i); } return sum; }
int main(int argc, char *argv[]) { /* принимаем только один аргумент, иначе - выход из программы */ if(argc != 2){ print_usage(); return 1; } int readfrom; int option; /* проверяем аргумент*/ while((option = getopt (argc, argv, "kfh")) != -1){ switch(option){ case 'k': readfrom = 0; break; case 'f': readfrom = 1; break; case 'h': default: print_usage(); return 1; } } stackT *stacks; int arraysize = 10; int c, n, i,j; int *tmp = (int *)malloc(10 * sizeof(int)); stacks = (stackT *)malloc(10 * sizeof(stackT)); if(readfrom == 0){ int n, offset; /* все вот это нужно для того, чтобы окончить ввод символом '\n' */ char line[1024]; j = 0; printf("введите числа: \n"); while(strcmp(line, "end")){ fgets(line, 1024, stdin); char *p = line; while(sscanf(p, " %d%n", &c, &n) == 1 ){ if(i == arraysize){ tmp = (int *) realloc(tmp, (arraysize+1) * sizeof(int)); /* увеличим массив, если не хватает места*/ if(tmp == NULL){ printf("Не смог выделить память"); exit(1); } arraysize++; } tmp[i++] = c; p += n; } StackInit(&stacks[j], arraysize); for(i = 0; i < arraysize; i++) StackPush(&stacks[j], tmp[i]); j++; tmp = (int *) realloc(tmp, (arraysize+1) * sizeof(int)); /* увеличим массив, если не хватает места*/ } } }
void ConvToRPNExp(char exp[LEN]) { Stack stack; int expLen = strlen(exp); char convExp[LEN]; int i, idx = 0; int flag_d = 0; char tok, popOp; StackInit(&stack); for(i=0; i<expLen; i++) { tok = exp[i]; if (isdigit(tok)){ convExp[idx++] = tok; } else if (tok == '.'){ convExp[idx++] = tok; } else { convExp[idx++] = ' '; switch(tok) { case '(': SPush(&stack, tok); break; case ')': while(1) { popOp = SPop(&stack); if(popOp == '(') break; convExp[idx++] = popOp; } break; case '+': case '-': case '*': case '/': while(!SIsEmpty(&stack) && WhoPrecOp(SPeek(&stack), tok) >= 0) convExp[idx++] = SPop(&stack); SPush(&stack, tok); break; } } } while(!SIsEmpty(&stack)) convExp[idx++] = SPop(&stack); convExp[idx] = '\0'; strcpy(exp, convExp); }
int main() { DWORD t = 0; //Needed because a bug in picc-18? MIWRL=0; MIWRH=0; TRISA = 0; TRISB = 0; TRISC = 0; TRISD = 0; TRISE = 0; TRISF = 0; TRISG = 0; PORTA=0; PORTB=0; PORTC=0; PORTD=0; PORTE=0; PORTF=0; OSCTUNE = 0x40; //Speed up to 41.67 MHz //Turn off AD ADCON1 = 0x0F; #if defined(DEBUG) && defined(_18F87J60) initUsart2(); #endif initTransmitter(); initReceiver(); initPwm(); initInterrupts(); initAppConfig(); initWDT(); TickInit(); StackInit(); //Set the LED on the connector SetLEDConfig(0x3742); //See MAC.h for the values printf("Telldus TellStick Net v%s\r\n", FIRMWARE_VERSION); while(1) { StackTask(); StackApplications(); if(TickGet() - t >= TICK_SECOND) { t = TickGet(); } #if defined(DEBUG) debugTask(); #endif rfReceiveTask(); discoveryTask(); ClrWdt(); } return 42; }
void main() { union { unsigned int32 hours; unsigned int8 minutes; unsigned int8 seconds;} upTime; TICK_TYPE CurrentTick,PreviousUDPTick,PreviousSATick; resetStatus = (RCON & 0b00111111) | !(STKPTR & 0b11000000); // Get the Reset Status RCON = RCON | 0b00111111; //Reset RCON Reset flags... (Reset Register) STKPTR = STKPTR & 0b00111111; // Clear Stack Overflow/Underflow flags PortInit(); OutputInit(); restart_wdt(); romEZHRInit(); //set up default ezhr settings eeROMinit(); //set up default eprom settings IPAddressInit(); //set up MAC and default IP addresses delay_ms(500); ADCInit(); //set up ADC ports iniADCParams(); SerialInit(); //set up serial ports TickInit(); //set up tick timer enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); StackInit(); WritePHYReg(ERXFCON,EthernetRXfilterSetting); // Allow only uni & multi SetLEDConfig(E_LED_CONFIG); // swap LED's output_high(E_SW_PWR_DN); // Power Ethernet Switch output_high(E_SW_RST); output_low(RS485_TXEN); output_high(RS485_RXDIS); output_high(RS232_F_OFF); output_high(RS232_F_ON); CurrentTick = PreviousUDPTick = get_ticks(); UDPSampleRate = eeReadUDPRate() * TICKS_PER_MILLISECOND; portControlInit(); while(TRUE) { CurrentTick = get_ticks(); restart_wdt(); StackTask(); restart_wdt(); MyTCPTask();//handles TCP connections restart_wdt(); setIO();// checks voltage status and sets ports accordingly //! if(CurrentTick-PreviousUDPTick >= UDPSampleRate) //! { //! currentRoutine=UDPTASK; //! BOOL UDPDone = MyUDPTask(); //! if(UDPDone) //! { //! PreviousUDPTick=CurrentTick; //! } //! } StackApplications(); } }
bool isValid(char *s) { int len = strlen(s); stackT left, right; StackInit(&left, len); StackInit(&right,len); int i; for(i = 0; i < len; i ++) { StackPush(&left, s[i]); } char a, b; while(!StackIsEmpty(&left)) { a = StackPop(&left); switch(a) { case '(': if(StackIsEmpty(&right)) return false; b = StackPop(&right); if( b != ')') return false; else break; case '[': if(StackIsEmpty(&right)) return false; b = StackPop(&right); if( b != ']') return false; else break; case '{': if(StackIsEmpty(&right)) return false; b = StackPop(&right); if( b != '}') return false; else break; case ')': StackPush(&right, a); break; case ']': StackPush(&right, a); break; case '}': StackPush(&right, a); break; default: printf("unrecognized char.\n"); } } if(StackIsEmpty(&right)) return true; return false; }
int main() { Stack *pStack; /* You should initialize the DS before any operations. */ int32_t rc = StackInit(&pStack); if (rc != SUCC) return rc; /* If you plan to delegate the resource clean task to the DS, please set the custom clean method. */ pStack->set_destroy(pStack, DestroyObject); /* Push items onto the queue. */ Employ* pEmploy = (Employ*)malloc(sizeof(Employ)); pEmploy->iId = 3; pEmploy->cLevel = 3; pEmploy->cYear = 3; pStack->push(pStack, (Item)pEmploy); pEmploy = (Employ*)malloc(sizeof(Employ)); pEmploy->iId = 2; pEmploy->cLevel = 2; pEmploy->cYear = 2; pStack->push(pStack, (Item)pEmploy); pEmploy = (Employ*)malloc(sizeof(Employ)); pEmploy->iId = 1; pEmploy->cLevel = 1; pEmploy->cYear = 1; pStack->push(pStack, (Item)pEmploy); /* Check the number of stored items. */ int32_t iSize = pStack->size(pStack); assert(iSize == 3); /* Retrieve the stack top item and delete it. */ Item item; pStack->top(pStack, &item); assert(((Employ*)item)->cLevel == 1); pStack->pop(pStack); pStack->top(pStack, &item); assert(((Employ*)item)->cLevel == 2); pStack->pop(pStack); pStack->top(pStack, &item); assert(((Employ*)item)->cLevel == 3); pStack->pop(pStack); /* You should deinitialize the DS after all the relevant tasks. */ StackDeinit(&pStack); return SUCC; }
int main(void) { MazeBoard *M1 = (MazeBoard *)malloc(sizeof(MazeBoard)); Stack *S1 = (Stack *)malloc(sizeof(Stack)); StackInit(S1); ShowMap(M1); while(TRUE) { } }
/**************************************************************************** Function: void ChipKITEthernetBegin(const BYTE *rgbMac, const BYTE *rgbIP, const BYTE *rgbGateWay, const BYTE *rgbSubNet, const BYTE *rgbDNS1, const BYTE *rgbDNS2) Description: This routine impements the Arduino Ethernet.Begin Method. This initializes the board, start supporting tasks, builds a default application configuration data structure, overrides the configuration structure if static IPs or assigned MACs are specified, and starts the Ethernet stack. Precondition: None Parameters: rgbMac - If all 6 bytes are zero, than use the internal MCU programed MAC address as defined by Microchip. It will be a unique MAC address in the Microchip range. The range will be somewhere starting with 00:04:A3:XX:XX:XX If non-zero, the specified MAC address will be used. rgbIP - If all 4 bytes are zero, then DHCP is used and rest of the parameters are ignored If an IP is specified then DHCP is not used and the IP represents a static IP address to use. The remainng parameters have value. rgbGateWay - 4 bytes IP address of the gateway to use. Only valid if rgbIP is specified rgbSubNet - 4 byte mask representing the subnet mask.Only valid if rgbIP is specified rgbDNS1 - 4 byte IP address of the primary DNS server. Only valid if rgbIP is specified. This value may be 0s if not required rgbDNS2 - 4 byte IP address of the secondary DNS server. Only valid if rgbIP is specifed. This value may be 0s if not required Returns: None Remarks: None ***************************************************************************/ void ChipKITEthernetBegin(const BYTE *rgbMac, const BYTE *rgbIP, const BYTE *rgbGateWay, const BYTE *rgbSubNet, const BYTE *rgbDNS1, const BYTE *rgbDNS2) { DWORD t = 0; const DWORD tDHCPTimeout = 30 * TICK_SECOND; // Initialize application specific hardware InitializeBoard(); // Initialize stack-related hardware components that may be // required by the UART configuration routines TickInit(); // Initialize Stack and application related NV variables into AppConfig. InitAppConfig(); // see if we have something other than to use our MAC address if((rgbMac[0] | rgbMac[1] | rgbMac[2] | rgbMac[3] | rgbMac[4] | rgbMac[5]) != 0) { memcpy(&AppConfig.MyMACAddr, rgbMac, 6); } // if we are not to use DHCP; fill in what came in. if((rgbIP[0] | rgbIP[1] | rgbIP[2] | rgbIP[3]) != 0) { AppConfig.Flags.bIsDHCPEnabled = FALSE; // don't use dhcp memcpy(&AppConfig.MyIPAddr, rgbIP, 4); memcpy(&AppConfig.MyGateway, rgbGateWay, 4); memcpy(&AppConfig.MyMask,rgbSubNet, 4); memcpy(&AppConfig.PrimaryDNSServer, rgbDNS1, 4); memcpy(&AppConfig.SecondaryDNSServer, rgbDNS2, 4); AppConfig.DefaultIPAddr = AppConfig.MyIPAddr; AppConfig.DefaultMask = AppConfig.MyMask; } // make sure our static array is zeroed out. memset(rgUDPSocketBuffers, 0, sizeof(rgUDPSocketBuffers)); // Initialize core stack layers (MAC, ARP, TCP, UDP) and // application modules (HTTP, SNMP, etc.) StackInit(); // arp will not work right until DHCP finishes // if DHCP won't configure after the timeout; then just go with it // maybe later it will configure, but until then, things might not work right. t = TickGet(); while(AppConfig.Flags.bIsDHCPEnabled && !DHCPIsBound(0) && ((TickGet() - t) < tDHCPTimeout)) { ChipKITPeriodicTasks(); } }
int main(void) { stackT stack; /* A stack to hold characters. */ char str[MAX]; /* String entered by user. */ char *traverse; /* Pointer used to traverse the string. */ /* * Get a string from the user--don't enter more * than 10 characters! */ printf("Enter a string <= 10 chars: "); fgets(str, MAX, stdin); /* Read line, discard newline. */ /* * Initialize the stack. Make it at least * big enough to hold the string we read in. */ StackInit(&stack, strlen(str)); /* * Traverse the string and put each * character on the stack. */ for (traverse = str; *traverse != '\0'; traverse++) { printf("Pushing: %c on to stack\n", *traverse); StackPush(&stack, *traverse); printf("Popped: %c from top of stack\n", StackPop(&stack)); } /* * Pop each of the characters off of * the stack and print them out. */ /* printf("\nPopped characters are: "); while (!StackIsEmpty(&stack)) { printf("%c", StackPop(&stack)); } */ printf("\n"); StackDestroy(&stack); return 0; }
void DFShowGraphVertex(ALGraph* pg, int startV) { Stack stack; int visitV = startV; int nextV; StackInit(&stack); VisitVirtex(pg, visitV); SPush(&stack, visitV); while( LFirst(&(pg->adjList[visitV]), &nextV) == TRUE ) { int visitFlag = FALSE; if(VisitVirtex(pg, nextV) == TRUE) // if nextV is the virtex that was visited { SPush(&stack, visitV); // Push nextV in the stack visitV = nextV; visitFlag = TRUE; } else // if nextV is not the virtex that was visited before { while(LNext(&(pg->adjList[visitV]),&nextV) == TRUE) { if( VisitVirtex(pg, nextV) == TRUE) { SPush(&stack, visitV); visitV = nextV; visitFlag = TRUE; break; } } } if(visitFlag == FALSE) { if(SIsEmpty(&stack) == TRUE) break; else visitV = SPop(&stack); } } memset(pg->visitInfo, 0, sizeof(int) * pg->numOfVertex); }
bool platform_initialize() { uint32_t lastIp; nabto_stamp_t timeout; // Configure TCP/IP stack stuff AppConfig.Flags.bIsDHCPEnabled = true; AppConfig.Flags.bInConfigMode = true; AppConfig.MyIPAddr.Val = MY_DEFAULT_IP_ADDR_BYTE1 | MY_DEFAULT_IP_ADDR_BYTE2 << 8ul | MY_DEFAULT_IP_ADDR_BYTE3 << 16ul | MY_DEFAULT_IP_ADDR_BYTE4 << 24ul; AppConfig.DefaultIPAddr.Val = AppConfig.MyIPAddr.Val; AppConfig.MyMask.Val = MY_DEFAULT_MASK_BYTE1 | MY_DEFAULT_MASK_BYTE2 << 8ul | MY_DEFAULT_MASK_BYTE3 << 16ul | MY_DEFAULT_MASK_BYTE4 << 24ul; AppConfig.DefaultMask.Val = AppConfig.MyMask.Val; AppConfig.MyGateway.Val = MY_DEFAULT_GATE_BYTE1 | MY_DEFAULT_GATE_BYTE2 << 8ul | MY_DEFAULT_GATE_BYTE3 << 16ul | MY_DEFAULT_GATE_BYTE4 << 24ul; AppConfig.PrimaryDNSServer.Val = MY_DEFAULT_PRIMARY_DNS_BYTE1 | MY_DEFAULT_PRIMARY_DNS_BYTE2 << 8ul | MY_DEFAULT_PRIMARY_DNS_BYTE3 << 16ul | MY_DEFAULT_PRIMARY_DNS_BYTE4 << 24ul; AppConfig.SecondaryDNSServer.Val = MY_DEFAULT_SECONDARY_DNS_BYTE1 | MY_DEFAULT_SECONDARY_DNS_BYTE2 << 8ul | MY_DEFAULT_SECONDARY_DNS_BYTE3 << 16ul | MY_DEFAULT_SECONDARY_DNS_BYTE4 << 24ul; TickInit(); StackInit(); unabto_microchip_arp_reset(); // Wait for dhcp. lastIp = AppConfig.MyIPAddr.Val; #if ENABLE_DHCP_BUG_WORKAROUND == 1 nabtoSetFutureStamp(&timeout, 5000); #endif NABTO_LOG_DEBUG(("Acquiring IP from DHCP server...")); while (lastIp == AppConfig.MyIPAddr.Val) { StackTask(); #if ENABLE_DHCP_BUG_WORKAROUND == 1 if (nabtoIsStampPassed(&timeout)) { Reset(); } #endif } READ_U32(lastIp, &AppConfig.MyIPAddr.Val); NABTO_LOG_DEBUG(("Got IP from DHCP server: "PRIip, MAKE_IP_PRINTABLE(lastIp))); return true; }
int main() { Stack stack; StackInit(&stack); SPush(&stack, 1);SPush(&stack, 2); SPush(&stack, 3);SPush(&stack, 4); SPush(&stack, 5); while(!SIsEmpty(&stack)) printf("%d ", SPop(&stack)); printf("\n"); return 0; }
void qsort_3 (int *arr, int size, const int numThreads) { //temp vals int i; //initialize stack stackT work; stackElementT element = {0, size-1}; StackInit (&work, 2*(size/SWITCH_THRESH+1)); StackPush (&work, element); //initialize all threads pthread_t *threads; threads = malloc (numThreads * sizeof(pthread_t)); /* if (posix_memalign((void **)&threads, sizeof(pthread_t), MAX_THRDS*sizeof(pthread_t))) { perror("posix_memalign"); exit(-1); } */ int busyThreads = 0; struct qsort_3_args shared_arg = {arr, &work, &busyThreads}; for (i = 0; i < numThreads; i++) { #ifdef DEBUG printf("Creating thread %d\n", i+1); #endif if (pthread_create(&threads[i], NULL, qsort_3_thread, &shared_arg)) { perror("pthread_create"); exit(-1); } } #ifdef DEBUG printf("Created all threads\n"); #endif //destroy all threads int status; for (i=0; i<numThreads; i++) { #ifdef DEBUG printf("Joining thread %d\n", i+1); #endif pthread_join(threads[i], (void **)&status); } #ifdef DEBUG printf("Joined all threads\n"); #endif free(threads); //destroy stack StackDestroy (&work); return; }
int main(void) { // Stack의 생성 및 초기화 /////// Stack stack; StackInit(&stack); // 데이터 넣기 /////// SPush(&stack, 1); SPush(&stack, 2); SPush(&stack, 3); SPush(&stack, 4); SPush(&stack, 5); // 데이터 꺼내기 /////// while (!SIsEmpty(&stack)) printf("%d ", SPop(&stack)); return 0; }
void MyWIFI_Start(void) { // Initialize stack-related hardware components TickInit(); #if defined(STACK_USE_MPFS2) MPFSInit(); #endif // Initialize Stack and application related NV variables into AppConfig. MyWIFI_InitAppConfig(); // Initialize core stack layers (MAC, ARP, TCP, UDP) and // application modules (HTTP, SNMP, etc.) StackInit(); // Connect to the my WIFI Network MyWIFI_Connect(); }
void InOrderNotRecurssion(BiTree T) { SqStack s; type p; s=StackInit(); p=T; while(p || !StackEmpty(s)) { if(p) { s=Push(s,p); p=p->lchild; } else { s=Pop(s,&p); printf("%c ",p->data); p=p->rchild; } } printf("\n"); DestroyStack(s); }
void InOrderUnrec(Bitree t) { SqStack s; StackInit(s); p=t; while (p!=null || !StackEmpty(s)) { while (p!=null) //遍历左子树 { push(s,p); p=p->lchild; }//endwhile if (!StackEmpty(s)) { p=pop(s); visite(p->data); //访问根结点 p=p->rchild; //通过下一次循环实现右子树遍历 }//endif }//endwhile }//InOrderUnrec
void PreOrderUnrec(Bitree t) { SqStack s; StackInit(s); //初始化栈 p=t; while (p!=null || !StackEmpty(s)) { while (p!=null) //遍历左子树 { visite(p->data); push(s,p); p=p->lchild; }//endwhile if (!StackEmpty(s)) //通过下一次循环中的内嵌while实现右子树遍历 { p=pop(s); p=p->rchild; }//endif }//endwhile }//PreOrderUnrec
int main(int argc, const char * argv[]) { // insert code here... int temp = 0; printf("Hello, World!\n"); STACK *pStack = StackInit(); StackPush(pStack, 1); StackPush(pStack, 2); StackPush(pStack, 3); StackPop(pStack, &temp); printf("%d \n",temp); StackPop(pStack, &temp); printf("%d \n",temp); return 0; }
/* * Main entry point. */ void main(void) { static TICK t = 0; BYTE c, i; WORD w; BYTE buf[10]; /* * Initialize any application specific hardware. */ InitializeBoard(); /* * Initialize all stack related components. * Following steps must be performed for all applications using * PICmicro TCP/IP Stack. */ TickInit(); /* * Initialize MPFS file system. */ MPFSInit(); //Intialize HTTP Execution unit htpexecInit(); //Initialze serial port serInit(); /* * Initialize Stack and application related NV variables. */ appcfgInit(); appcfgUSART(); //Configure the USART #ifdef SER_USE_INTERRUPT //Interrupt enabled serial ports have to be enabled serEnable(); #endif appcfgCpuIO(); // Configure the CPU's I/O port pins appcfgADC(); // Configure ADC unit appcfgPWM(); // Configure PWM unit //Clear Screen serPutRomString(AnsiEscClearScreen); /* * Wait a couple of seconds for user input. * - If something is detected, start config. * - If nothing detected, start main program. */ serPutRomString(PressKeyForConfig); for (i = 60; i > 0; --i) //Delay for 50mS x 60 = 3 sec { if ((i % 8) == 0) serPutByte('.'); if (serIsGetReady()) { SetConfig(); break; } DelayMs(50); } serPutByte('\r'); serPutByte('\n'); StackInit(); #if defined(STACK_USE_HTTP_SERVER) HTTPInit(); #endif #if defined(STACK_USE_FTP_SERVER) && defined(MPFS_USE_EEPROM) FTPInit(); #endif #if defined(STACK_USE_DHCP) || defined(STACK_USE_IP_GLEANING) if (!AppConfig.Flags.bIsDHCPEnabled ) { /* * Force IP address display update. */ myDHCPBindCount = 1; #if defined(STACK_USE_DHCP) DHCPDisable(); #endif } #endif #if defined( STACK_USE_VSCP ) vscp2_udpinit(); // init VSCP subsystem #endif /* * Once all items are initialized, go into infinite loop and let * stack items execute their tasks. * If application needs to perform its own task, it should be * done at the end of while loop. * Note that this is a "co-operative mult-tasking" mechanism * where every task performs its tasks (whether all in one shot * or part of it) and returns so that other tasks can do their * job. * If a task needs very long time to do its job, it must broken * down into smaller pieces so that other tasks can have CPU time. */ while ( 1 ) { /* * Blink SYSTEM LED every second. */ if ( TickGetDiff( TickGet(), t ) >= TICK_SECOND/2 ) { t = TickGet(); LATB6 ^= 1; } //Perform routine tasks MACTask(); /* * This task performs normal stack task including checking * for incoming packet, type of packet and calling * appropriate stack entity to process it. */ StackTask(); #if defined(STACK_USE_HTTP_SERVER) /* * This is a TCP application. It listens to TCP port 80 * with one or more sockets and responds to remote requests. */ HTTPServer(); #endif #if defined(STACK_USE_FTP_SERVER) && defined(MPFS_USE_EEPROM) FTPServer(); #endif /* * In future, as new TCP/IP applications are written, it * will be added here as new tasks. */ /* * Add your application speicifc tasks here. */ ProcessIO(); /* XEEBeginRead( EEPROM_CONTROL, 0x0530 ); while ( 1 ) { c = XEERead(); c = 1; } //c = XEERead(); XEEEndRead(); */ #if defined( STACK_USE_VSCP ) vscp2_Task(); #endif /* * For DHCP information, display how many times we have renewed the IP * configuration since last reset. */ if ( DHCPBindCount != myDHCPBindCount ) { DisplayIPValue(&AppConfig.MyIPAddr, TRUE); myDHCPBindCount = DHCPBindCount; } } }