<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      C語言【數據結構】線性表--棧

      線性表-棧-順序存儲

      sqstack.h
      typedef int data_type;
      
      typedef struct {
      	data_type * data;
      	int maxlen;
      	int top;
      }sqstack;
      
      sqstack * stack_create(int len);
      int stack_push(sqstack * s, data_type value);
      int stack_empty(sqstack * s);
      int stack_full(sqstack * s);
      data_type stack_pop(sqstack * s);
      data_type stack_top(sqstack * s);
      int stack_clear(sqstack * s);
      int stack_show(sqstack * s);
      int stack_free(sqstack *s);
      
      sqstack.c
      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      #include "sqstack.h"
      
      sqstack * stack_create(int len){
      	sqstack * s;
      	s = (sqstack *)malloc(sizeof(sqstack));
      	if(s==NULL){
      		printf("%s\n", "malloc sqstack failed\n");
      		return NULL;
      	}
      
      	data_type * p;
      	p = (data_type *)malloc(len * sizeof(data_type));
      	if(p==NULL){
      		printf("%s\n", "malloc data failed\n");
      		// 數組內存申請失敗,則棧內存也應該釋放
      		free(s);
      		return NULL;
      
      	}
      
      	memset(p, 0, len *sizeof(data_type));
      	s->data = p;
      	s->maxlen = len;
      	s->top = -1;
      
      	return s;
      }
      
      int stack_push(sqstack * s, data_type value){
      	if(s==NULL){
      		printf("stack is NULL\n");
      		return -1;
      	}
      	if(s->top==s->maxlen-1){
      		printf("stack is full\n");
      		return -1;
      	}
      	s->top++;
      	s->data[s->top] = value;
      	
      	return 0;
      }
      
      int stack_empty(sqstack * s){
      	if(s==NULL){
      		printf("stack is NULL\n");
      		return -1;
      	}
      	// 三目運算符
      	return (s->top == -1 ? 1 : 0);
      }
      int stack_full(sqstack * s){
      	if(s==NULL){
      		printf("stack is NULL\n");
      		return -1;
      	}
      	return (s->top == s->maxlen-1 ? 1 : 0);
      }
      data_type stack_pop(sqstack * s){
      	s->top--;
      	return s->data[s->top+1];
      }
      data_type stack_top(sqstack * s){
      	return s->data[s->top];
      }
      int stack_clear(sqstack * s){
      	s->top = -1;
      	return 0;
      }
      int stack_free(sqstack * s){
      	if(s==NULL){
      		printf("stack is NULL\n");
      		return -1;
      	}
      	if(s->data != NULL){
      		free(s->data);
      	}
      	free(s);
      	return 0;
      }
      int stack_show(sqstack * s){
      	if(s==NULL){
      		printf("stack is NULL\n");
      		return -1;
      	}
      	int i;
      	for (i = 0; i <= s->top; i++){
      		printf("%d\n", s->data[i]);
      	}
      	return 0;
      }
      
      test.c
      #include <stdio.h>
      #include <stdlib.h>
      #include "sqstack.h"
      
      int main(int argc, char const *argv[]){
      	sqstack * s;
      	s = stack_create(10);
      	stack_push(s, 10);
      	stack_push(s, 20);
      	stack_push(s, 30);
      
      	stack_show(s);
      
      	printf("top: %d\n",stack_top(s));
      
      	while(!stack_empty(s)){
      		printf("pop: %d\n", stack_pop(s));
      	}
      	
      	return 0;
      }
      

      線性表-棧-鏈式存儲

      linkstack.h
      typedef int data_type;
      
      typedef struct node{
      	data_type data;
      	struct node * next;
      }linkstack;
      
      
      linkstack * stack_create();
      int stack_push(linkstack * s, data_type value);
      int stack_empty(linkstack * s);
      data_type stack_pop(linkstack * s);
      data_type stack_top(linkstack * s);
      int stack_show(linkstack * s);
      int stack_free(linkstack *s);
      
      linkstack.c
      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      #include "linkstack.h"
      
      linkstack * stack_create(){
      	linkstack * s;
      	s = (linkstack *)malloc(sizeof(linkstack));
      	if(s==NULL){
      		printf("%s\n", "malloc failed\n");
      		return NULL;
      	}
      	s->data = 0;
      	s->next = NULL;
      	return s;
      
      }
      int stack_push(linkstack * s, data_type value){
      	if(s==NULL){
      		printf("%s\n", "linkstack is NULL\n");
      		return -1;
      	}
      	linkstack * p;
      	p = (linkstack *)malloc(sizeof(linkstack));
      	if(p==NULL){
      		printf("%s\n", "malloc failed\n");
      		return -1;
      	}
      	p->data = value;
      	// p->next = NULL;
      	p->next = s->next;
      	s->next = p;
      	return 0;
      
      }
      int stack_empty(linkstack * s){
      	if(s==NULL){
      		printf("%s\n", "linkstack is NULL\n");
      		return -1;
      	}
      	return (s->next == NULL ? 1 : 0);
      }
      data_type stack_pop(linkstack * s){
      	if(s==NULL){
      		printf("%s\n", "linkstack is NULL\n");
      		return -1;
      	}
      	linkstack * p;
      	p = s->next;
      	data_type data;
      	data = p->data;
      	s->next = p->next;
      	free(p);
      	p = NULL;
      	return data;
      
      }
      data_type stack_top(linkstack * s){
      	if(s==NULL){
      		printf("%s\n", "linkstack is NULL\n");
      		return -1;
      	}
      	return s->next->data;
      }
      int stack_show(linkstack * s){
      	if(s == NULL){
      		printf("%s\n", "linkstack is null");
      		return -1;
      	}
      
      	linkstack * p;
      	p = s;
      	while(p->next != NULL){
      		printf("%d\n", p->next->data);
      		p = p->next;
      	}
      	puts("");
      
      	return 0;
      }
      int stack_free(linkstack *s){
      	if(s==NULL){
      		printf("%s\n", "linkstack is NULL\n");
      		return -1;
      	}
      	linkstack *p;
      	while(s!=NULL){
      		p = s;
      		s = s->next;
      		printf("free: %d\n", p->data);
      		free(p);
      		p = NULL;
      	}
      	return 0;
      }
      
      test.c
      #include <stdio.h>
      #include <stdlib.h>
      #include "linkstack.h"
      
      int main(int argc, char const *argv[]){
      	linkstack * s;
      	s = stack_create();
      	stack_push(s, 10);
      	stack_push(s, 20);
      	stack_push(s, 30);
      
      	stack_show(s);
      
      	printf("top: %d\n",stack_top(s));
      	while(!stack_empty(s)){
      		printf("pop: %d\n", stack_pop(s));
      	}
      	stack_free(s);
      
      	return 0;
      }
      
      posted @ 2023-10-15 01:35  揚帆去遠航  閱讀(29)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 白白色发布永久免费观看视频 | 久久精品一本到99热免费| 99福利一区二区视频| 人妻少妇精品视频无码综合| 中文字幕日韩一区二区不卡| 金昌市| 激情综合色综合啪啪五月| 亚洲综合网国产精品一区| 蜜桃成熟色综合久久av| 亚洲第一极品精品无码久久| 国产美女被遭强高潮免费一视频| 亚洲熟妇自偷自拍另类| 成人一区二区不卡国产| 国产一区二区一卡二卡| 国产成人人综合亚洲欧美丁香花| 亚洲精品日本一区二区| 国产精品久久久久久久网| a4yy私人毛片| 色一乱一伦一图一区二区精品| 乱色欧美激惰| 精品视频一区二区| 国产成人黄色自拍小视频| 午夜福利国产盗摄久久性| 成人永久免费A∨一级在线播放| 午夜通通国产精品福利| 成人亚洲一级午夜激情网| 国产精品无码无片在线观看3d| 国产麻豆剧果冻传媒一区 | 东乌| 精品尤物TV福利院在线网站 | 亚洲 日本 欧洲 欧美 视频| 中文字幕av高清片| 久久国产精品伊人青青草| 无码国产偷倩在线播放| 蜜臀98精品国产免费观看 | 成av人电影在线观看| 亚洲AV无码午夜嘿嘿嘿| 国产中文字幕一区二区| 宅男噜噜噜66在线观看| 日本中文一二区有码在线| 精品久久8x国产免费观看|