Commits

liangsdu committed ee5944d

linear list init

Comments (0)

Files changed (2)

+/**
+	Copyright (C) liangsdu.com All rights reserved.
+	   Date: 2010-10-03
+	 Author: liangsdu (AT) gmail.com
+    线性表 -- 链式实现(带头节点)
+**/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define OK          0
+#define ERROR       -1
+#define OVERTHROW   -2
+
+typedef int ElemType;
+
+typedef struct LNode{
+	ElemType data;		        // 数据域
+	struct LNode *next;			// 指针域
+}LNode, *linklist;
+
+int Linklist_init(linklist L)
+{
+    L = (Linklist) malloc(sizeof(struct LNode));
+    if(!L) exit(OVERTHROW);
+    L->next = NULL;
+    return OK;
+}
+
+int Linklist_clear(Linklist L)
+/**
+	Copyright (C) liangsdu.com All rights reserved.
+	   Date: 2010-10-03
+	 Author: liangsdu (AT) gmail.com
+    线性表 -- 顺序实现
+    C语言中没有“引用”,只有指针
+**/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+#define LIST_INIT_SIZE 100
+#define LIST_INCREMENT 10
+
+#define OK          0
+#define ERROR       -1
+#define OVERTHROW   -2
+
+typedef int ElemType;
+
+typedef struct {
+	ElemType *elem;		// 存储空间基址
+	int length;			// 当前长度
+	int listsize;
+}Sqlist;
+
+int Sqlist_init(Sqlist *L)          // 构造空表
+{
+	L->elem = (ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
+	if(!L->elem) exit(OVERTHROW);
+	L->length = 0;
+	L->listsize = LIST_INIT_SIZE;
+	return OK;
+}
+
+int Sqlist_clear(Sqlist *L)         // 表置空
+{
+
+}
+
+int Sqlist_destroy(Sqlist *L)       // 表销毁
+{
+
+}
+
+int Sqlist_insert(Sqlist *L, int i, ElemType e)     // 表插入第i个位置
+{
+    if(i < 1 || i > L->length + 1)
+        return ERROR;
+}
+
+
+int Sqlist_delete(Sqlist *L, int i, ElemType *e)    // 删除第i个元素,返回e
+{
+
+}
+
+int Sqlist_locate()         //zhao
+{
+
+}
+
+/* 遍历顺序表,需自己实现visit函数 */
+void Sqlist_traverse(Sqlist L, void (*visit)ElemType e)
+
+int main(void)
+{
+	Sqlist *L;
+
+}