日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

数据结构趣题——顺序表就地逆置

發(fā)布時(shí)間:2024/8/22 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数据结构趣题——顺序表就地逆置 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

利用原表的存儲(chǔ)空間將順序表(a1,a2,……,an)逆置為(an,an-1,………a1)。

1: #include <stdio.h> 2: #include <stdlib.h> 3:? 4: # define MAXSIZE 10 5: typedef struct { 6: int * base; 7: int length; 8: } sqlist ; 9:? 10: void reverseSQ(sqlist *l) { 11: int low = 0 , high = l->length - 1; 12: int buf , i; 13:? 14: for(i = 0; i < l->length / 2; i++) 15: { 16: buf = l->base[low] ; 17: l->base[low] = l->base[high]; 18: l->base[high] = buf; 19: low++; 20: high--; 21: } 22: } 23:? 24: int main() 25: { 26: sqlist l; 27: int a , i = 0; 28: /*創(chuàng)建一個(gè)順序表*/ 29: l.base = (int *)malloc(sizeof(int) * MAXSIZE); 30: l.length = 0; 31:? 32: /*輸入數(shù)據(jù)*/ 33: printf("Please input below 10 integer into the sqlist\n") ; 34: printf("Type -1 for stopping input\n"); 35: scanf("%d", &a); 36:? 37: while(a != -1 && i <= 9) 38: { 39: l.base[i] = a; 40: l.length++; 41: i++; 42: scanf("%d", &a); 43: } 44:? 45: /*輸出原順序表中的數(shù)據(jù)*/ 46: printf("The contents of the sqlist are\n"); 47:? 48: for(i = 0; i < l.length; i++) 49: printf("%d ", l.base[i]); 50:? 51: printf("\n"); 52:? 53: reverseSQ(&l); /*就地逆置順序表*/ 54:? 55:? 56: /*輸出逆置后的順序表中的數(shù)據(jù)*/ 57: printf("The contents of the reversed sqlist are\n"); 58:? 59: for(i = 0; i < l.length; i++) 60: printf("%d ", l.base[i]); 61:? 62: return 0; 63: }

轉(zhuǎn)載于:https://www.cnblogs.com/steven_oyj/archive/2010/05/28/1745941.html

與50位技術(shù)專(zhuān)家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的数据结构趣题——顺序表就地逆置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。