In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "how to achieve the order table in web", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to achieve the sequence table in web" this article.
Seqlist.h
# ifndef _ SEQLIST_H__ # define _ SEQLIST_H__ # include # define INIT_SIZE 2 # define ADD_SIZE 3 typedef int DataType; typedef struct Seqlist {DataType * data; int size; / / the number of elements stored in the current space int capacity / / maximum storage capacity of current space} Seqlist,*pSeqlist; void InitSeqlist (pSeqlist pSeq); void DestorySeqlist (pSeqlist pSeq); void PushBack (pSeqlist pSeq,DataType x); void PopBack (pSeqlist pSeq); void PushFront (pSeqlist pSeq,DataType x); void PopFront (pSeqlist pSeq); void Remove (pSeqlist pSeq,DataType x); void RemoveAll (pSeqlist pSeq,DataType x); void BubbleSort (pSeqlist pSeq); void InsertSort (pSeqlist pSeq) Void SelectSort (pSeqlist pSeq); int BinarySearch (pSeqlist pSeq,DataType x); void Erase (pSeqlist pSeq,int pos); void PrintSeqlist (pSeqlist pSeq); # endif / / SEQLIST_D_H__
Seqist.c
# include "seqlist.h" void InitSeqlist (pSeqlist pSeq) {pSeq- > data = (DataType *) malloc (INIT_SIZE*sizeof (DataType)); if (pSeq- > data = = NULL) {printf ("out of memory\ n"); exit (1);} pSeq- > size = 0; pSeq- > capacity = INIT_SIZE / / set the capacity to the maximum storage capacity of the current space} void DestorySeqlist (pSeqlist pSeq) {free (pSeq- > data); pSeq- > data = NULL; pSeq- > size = 0; pSeq- > capacity = 0;} void CheckCapacity (pSeqlist pSeq) / / check whether the current space is full {assert (pSeq) If (pSeq- > size = = pSeq- > capacity) / / if full, expand {DataType * tmp = NULL; tmp = (DataType *) realloc (pSeq- > data, (pSeq- > capacity + = ADD_SIZE) * sizeof (DataType)); if (NULL = = tmp) {printf ("out of memory\ n") Exit (1);} pSeq- > data = tmp;}} void PushBack (pSeqlist pSeq, DataType x) {assert (pSeq); CheckCapacity (pSeq); / / whenever you insert an element, first check whether the space is full pSeq- > data [PSEQ-> size++] = x / / size will also change after inserting elements} void PopBack (pSeqlist pSeq) {assert (pSeq); if (pSeq- > size = = 0) / / abnormal case, table has been empty {printf ("table is empty\ n"); return;} pSeq- > size--;} void PushFront (pSeqlist pSeq, DataType x) {int I = 0 Assert (pSeq); CheckCapacity (pSeq); / / whenever you insert an element, first check whether the space is full for (I = pSeq- > size; I > 0; iMurray -) / / move the data from back to front {pSeq- > data [I] = pSeq- > data [I-1];} pSeq- > data [0] = x; pSeq- > size++ } void PopFront (pSeqlist pSeq) {int I = 0; assert (pSeq); if (pSeq- > size = = 0) / / exception, table empty {printf ("table is empty\ n"); return;} for (I = 0; I
< pSeq->Size-1; iTunes +) / / overrides {pSeq- > data [I] = pSeq- > data [I + 1] directly from the second element;} pSeq- > size--;} void Remove (pSeqlist pSeq, DataType x) / / deletes the first occurrence x {int I = 0; int j = 0; assert (pSeq); for (I = 0; I
< pSeq->Size; iTunes +) {if (pSeq- > data [I] = = x) {for (j = I; j)
< pSeq->Size-1; jacks +) / / overrides {pSeq- > data [j] = pSeq- > data [j + 1];} pSeq- > size--; return;} void RemoveAll (pSeqlist pSeq, DataType x) {int I = 0; int j = 0 when deleted. Assert (pSeq); for (I = 0; I
< pSeq->Size; iTunes +) {if (pSeq- > data [I] = = x) {for (j = I; j)
< pSeq->Size- 1; jacks +) / / overrides {pSeq- > data [j] = pSeq- > data [j + 1];} pSeq- > size--;} void BubbleSort (pSeqlist pSeq) {int flag = 0; int I = 0; int j = 0 when deleted Int k = pSeq- > size-1; assert (pSeq); for (I = 0; I
< pSeq->Size-1; iMel -) {int m = 0; flag = 1; / / set the tag to 1 for (j = 0; j
< k; j++) { if (pSeq->Data [j] > pSeq- > data [j + 1]) {DataType tmp = pSeq- > data [j]; pSeq- > data [j] = pSeq- > data [j + 1]; pSeq- > data [j + 1] = tmp; flag = 0; m = j / / record the position of the last exchange}} if (flag) / / Mark bit 1 indicates that it has been ordered {return;} m = k / / set k to the position of the last exchange}} void InsertSort (pSeqlist pSeq) / / insert sort {int I = 0; int j = 0; assert (pSeq); for (I = 1; I
< pSeq->Size; iTunes +) {DataType tmp = pSeq- > data [I]; for (j = iMuth1; j > = 0; jMui -) {if (pSeq- > data [j] > tmp) {pSeq- > data [Jaim1] = pSeq- > data [j];} else {break }} pSeq- > data [jacks 1] = tmp;}} void SelectSort (pSeqlist pSeq) {int I = 0; int j = 0; int k = 0; assert (pSeq); for (I = 0; I
< pSeq->Size; iTunes +) {k = I; for (j = I + 1; j
< pSeq->Size; jacks +) {if (pSeq- > data [k] > pSeq- > data [j]) {k = j;}} if (k! = I) {DataType tmp = pSeq- > data [k]; pSeq- > data [k] = pSeq- > data [I] PSeq- > data [I] = tmp;}} int BinarySearch (pSeqlist pSeq, DataType x) {int left = 0; int right = pSeq- > size-1 political int mid=0; assert (pSeq); mid= (left&right) + ((left ^ right) > > 1); / / average while (left data [mid] > x) {right = mid-1 } else if (pSeq- > data [mid])
< x) { left = mid + 1; } else { return mid; } } return -1; } void Erase(pSeqlist pSeq, int pos) { int i = 0; assert(pSeq); if (pos>= pSeq- > size&&pos
< 0) { printf("删除位置不合法\n"); return; } for (i = pos; i < pSeq->Size- 1; iTunes +) / / overrides {pSeq- > data [I] = pSeq- > data [I + 1] forward after pos;} pSeq- > size--;} void PrintSeqlist (pSeqlist pSeq) {int I = 0 int assert (pSeq); if (pSeq- > size = 0) {printf ("table is empty\ n"); return } for (I = 0; I
< pSeq->Size; iTunes +) {printf ("% d", pSeq- > data [I]);} printf ("\ n");}
Test.c
# include "seqlist.h" void menu () {printf ("0.exit 1.PrintSeqlist\ n"); printf ("2.InitSeqlist 3.PushBack\ n"); printf ("4.Popback 5.PushFornt\ n"); printf ("6.PopFornt 7.Erase\ n"); printf ("8.Remove 9.RemoveAll\ n") Printf ("10.BubbleSort 11.BinarySearch\ n"); printf ("12.DestorySeqlist 13.InsertSort\ n"); printf ("14.SelectSort\ n"); printf ("Please enter: >");} void test (pSeqlist pSeq) {DataType x = 0 DataType ret=0; while n = 0 DataType ret=0; while (1) {menu () Scanf ("% d", & n); switch (n) {case 0: exit (1); break; case 1: PrintSeqlist (pSeq); break; case 2: InitSeqlist (pSeq); break Case 3: printf ("Please enter elements\ n"); scanf ("% d", & x); PushBack (pSeq, x); break; case 4: PopBack (pSeq); break; case 5: printf ("Please enter elements\ n") Scanf ("% d", & x); PushFront (pSeq, x); break; case 6: PopFront (pSeq); break; case 7: printf ("Please enter deletion location\ n"); scanf ("% d", & pos) Erase (pSeq, pos); break; case 8: printf ("Please enter elements\ n"); scanf ("% d", & x); Remove (pSeq, x); break; case 9: printf ("Please enter elements\ n") Scanf ("% d", & x); RemoveAll (pSeq, x); break; case 10: BubbleSort (pSeq); break; case 11: printf ("Please enter elements\ n"); scanf ("% d", & x); ret=BinarySearch (pSeq, x) If (ret = =-1) printf ("without this element\ n"); printf ("subscript:% d\ n", ret); break; case 12: DestorySeqlist (pSeq); break; case 13: InsertSort (pSeq); break Case 14: SelectSort (pSeq); break; default: printf ("invalid input\ n"); break;}} int main () {Seqlist pSeq; test (& pSeq); system ("pause"); return 0 } these are all the contents of the article "how to implement the order Table in web". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.