Skip to content

Commit

Permalink
add static table define
Browse files Browse the repository at this point in the history
 c ,add static table define
  • Loading branch information
bing1zhi2 committed Aug 6, 2019
1 parent 54b767e commit 66fe647
Show file tree
Hide file tree
Showing 13 changed files with 491 additions and 436 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

*.class
*.o
*.o
*.exe
3 changes: 3 additions & 0 deletions cPractice/datastructure/datastructure.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<Unit filename="src/sequence_table.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/static_table.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<code_completion />
<envvars />
Expand Down
18 changes: 18 additions & 0 deletions cPractice/datastructure/datastructure.depend
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,21 @@

1562835019 f:\code\mycode\c\datastructer\datastructure\include\common_define.h

1562294963 source:f:\code\mycode\algorithmpractice\cpractice\datastructure\src\removedup.c
"removeDup.h"

1562294789 f:\code\mycode\algorithmpractice\cpractice\datastructure\include\removedup.h

1564483905 source:f:\code\mycode\algorithmpractice\cpractice\datastructure\main.c
<stdio.h>
<stdlib.h>
"removeDup.h"
"common_define.h"

1565025551 f:\code\mycode\algorithmpractice\cpractice\datastructure\include\common_define.h

1564483877 source:f:\code\mycode\algorithmpractice\cpractice\datastructure\src\sequence_table.c
<stdio.h>
<stdlib.h>
<common_define.h>

23 changes: 14 additions & 9 deletions cPractice/datastructure/datastructure.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="include\removeDup.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="include\common_define.h" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="167" topLine="0" />
<Cursor1 position="437" topLine="7" />
</Cursor>
</File>
<File name="src\removeDup.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1262" topLine="9" />
<Cursor1 position="105" topLine="1" />
</Cursor>
</File>
<File name="main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\static_table.c" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="246" topLine="0" />
<Cursor1 position="120" topLine="0" />
</Cursor>
</File>
<File name="include\common_define.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\removeDup.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="186" topLine="0" />
<Cursor1 position="672" topLine="21" />
</Cursor>
</File>
<File name="src\sequence_table.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="286" topLine="0" />
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="include\removeDup.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="130" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
17 changes: 17 additions & 0 deletions cPractice/datastructure/include/common_define.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#ifndef COMMON_DEFINE_H_INCLUDED
#define COMMON_DEFINE_H_INCLUDED
#define MAXSIZE 1000
typedef int ElemType;


typedef struct{
char name[20];
Expand All @@ -12,4 +15,18 @@ typedef struct{
int length;
}SqList;


/* 静态链表相关 */
typedef struct{
ElemType data;
int next;
}SNode;

typedef struct{
SNode sd[MAXSIZE];
int SL,AV; /* 两个头指针*/
int SLinksize;

}StaticLink;

#endif // COMMON_DEFINE_H_INCLUDED
26 changes: 25 additions & 1 deletion cPractice/datastructure/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,34 @@ int main()
// ===== 删除排序数组中多出来的元素======================
// testRemoveDup();


// 初始化顺序表
SqList L;
if(initSqlList(&L,10))
printf("success");
printf("success \n");
printf(" %d ", L.length+1);
STD std;
strcpy(std.name,"test");
std.score= 90;


int re = insertSqlList(&L,L.length+1,std);
if(re){
printf("insert success \n");
}

STD std2;
strcpy(std.name,"张三");
std2.score= 99;
insertSqlList(&L,L.length+1,std2);

std2.score= 98;


printfSqlList(L);

updateSqlList(&L,2,std2);
printfSqlList(L);


return 0;
Expand Down
47 changes: 46 additions & 1 deletion cPractice/datastructure/src/sequence_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


int initSqlList(SqList *L, int max){
L->data =(STD*) malloc(sizeof(STD)*max );
L->data =(STD *) malloc(max* sizeof(STD) );
if(L->data == NULL){
printf("init failed...\n");
return 0;
Expand All @@ -13,3 +13,48 @@ int initSqlList(SqList *L, int max){
L->length = 0;
return 1;
}

//后移让位置 ,插入,注意这里从1开始,实际存储在0上
int insertSqlList(SqList *L,int i,STD std){

if(i<1|| i> L->length+1){
printf("pos error...");
};
if(L->length > L->listsize){
printf("容量不够");
};
int j;
for(j=L->length ; j>=i; j--){
L->data[j] = L->data[j-1];
}
L->data[i-1]= std;
L->length=L->length + 1;
return 1;
}

//删除, 前移
int deleteSqlList(SqList *L, int i, STD *std){

*std = L->data[i-1];
int k;
for(k=i-1; k< L->length;k++){
L->data[k-1] = L->data[k];
}
L->length = L->length -1;
return 1;
}

int updateSqlList(SqList *L, int i, STD std){
L->data[i-1] = std;
return 1;
}

void printfSqlList(SqList L){
int i;
for(i=0;i<L.length;i++){
printf(" %10s ",L.data[i].name);
printf(" %7.2f ",L.data[i].score);
}
printf("--------------------- \n");
}

9 changes: 9 additions & 0 deletions cPractice/datastructure/src/static_table.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include<stdio.h>
#include<stdlib.h>
#include<common_define.h>

int initSLink(StaticLink *L)
{
L->SL=0;

}
Loading

0 comments on commit 66fe647

Please sign in to comment.