plist.c

来自「压缩包里面的都是精致的基本C语言小程序」· C语言 代码 · 共 91 行

C
91
字号
#include <stdio.h>#include "mystdlib.h"#include "error.h"#include "tuple.h"#include "linkedList.h"#include "commonInter.h"#include "plist.h"struct plist{  linkedList list;};plist newPlist (){  plist p = checkedMalloc (sizeof (*p));  p->list = newLinkedList ();    return p;}void plistAdd (plist list, tag t, poly x){  tuple tp = newTuple (t, x);  linkedListInsertHead (list->list, tp);    return;}poly plistPeek (plist list, tag t){  linkedList temp = linkedListGetFirst (list->list);  while (temp)  {    tuple tp = (tuple)temp->data;    if (tagEquals (t, tupleFirst (tp)))    {      //  printf ("they are equals\n");      return tupleSecond (tp);    }        temp = temp->next;  }  //error ("\ndata item not found in property list\n");  return NULL;}void plistDeleteAll (plist list, tag t){  linkedList prev = list->list;  linkedList cur = linkedListGetFirst (prev);  while (cur)  {    tuple tp = (tuple)cur->data;    if (tagEquals (t, tupleFirst (tp)))    {      prev->next = cur->next;      checkedFree (cur);      cur = prev->next;    }    else    {      prev = cur;      cur = cur->next;    }  }    return;}void plistOutput (plist l){  linkedList temp = linkedListGetFirst (l->list);  while (temp)  {    tuple tp = (tuple)temp->data;    poly data = tupleSecond (tp);    strOutput (getVft (data)->toString(data));    temp = temp->next;  }}int plistEquals (plist l1, plist l2){  return l1==l2;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?