资源简介
多线程实现双向链表的增删改 其中的信号量设成一个也行- -
代码片段和文件信息
#include
#include
#include
#include
HANDLE sem;
HANDLE tem;
HANDLE uem;
HANDLE vem;
typedef int Datatype;
typedef struct Point
{
struct Point *prior *next;
Datatype number;
}Point *Pointlist;
typedef struct ProcParam
{
Pointlist a;
};
Pointlist InitList()
{
srand((unsigned)time(NULL));
Pointlist head;
Datatype data;
head = (Pointlist)malloc(sizeof(Point));
head->number = NULL;
head->prior = NULL;
head->next = NULL;
return head;
}
Insert(Pointlist head)
{
int i = 0;
WaitForSingleobject(sem INFINITE);
srand((unsigned)time(NULL));
Pointlist p1 p2;
p1 = head;
if (p1->number == NULL)
{
p1->number = (rand() % 10) + 1;
printf(“插入元素%d\n“ p1->number);
Sleep(500);
}
else
while (p1->next != NULL)
{
p1 = p1->next;
}
for (i = 0; i < 3; i++)
{
p2 = (Pointlist)malloc(sizeof(Point));
p2->prior = p1;
p1->next = p2;
p2->number = (rand() % 10 + 1);
p2->next = NULL;
p1 = p2;
printf(“插入元素%d\n“ p2->number);
Sleep(500);
}
ReleaseSemaphore(sem 1 NULL);
return head;
}
Pointlist find(Pointlist head)
{
WaitForSingleobject(vem INFINITE);
srand((unsigned)time(NULL));
Pointlist p;
p = head;
int i = 1 c = (rand() % 10) + 2;
printf(“查找元素%d的位置\n“c);
while (p != NULL && p->number != c)
{
++i;
p = p->next;
}
if (p == NULL)
{
printf(“无此节点\n“);
ReleaseSemaphore(vem 1 NULL);
return 0;
}
else
printf(“在链表中的位置为:%d\n“ i);
ReleaseSemaphore(vem 1 NULL);
}
Pointlist Insert2(Pointlist head)
{
WaitForSingleobject(tem INFINITE);
int i a;
srand((unsigned)time(NULL));
i = (rand() % 10) + 2;
a = (rand() % 10);
printf(“在位置%d中插入元素%d\n“ i a);
Sleep(500);
Pointlist p s;
p = head;
int tempi;
if (i>10)
{
printf(“无此位置的节点\n“);
Sleep(500);
ReleaseSemaphore(tem 1 NULL);
return head;
}
if (i == 1)
{
s = (Pointlist)malloc(sizeof(Point));
s->number = a;
s->prior = NULL;
s->next = p;
p->prior = s;
head = s;
print(head);
Sleep(500);
ReleaseSemaphore(tem 1 NULL);
return head;
}
else
{
for (tempi = 1; tempi < i - 1; tempi++)
{
p = p->next;
}
s = (Pointlist)malloc(sizeof(Point));
s->number = a;
s->next = p->next;
p->next->prior = s;
s->prior = p;
p->next = s;
print(head);
Sleep(500);
ReleaseSemaphore(tem 1 NULL);
return head;
};
}
Pointlist Erase(Pointlist head)
{
WaitForSingleobject(uem INFINITE);
int i;
srand((unsigned)time(NULL));
i = (rand() % 10) + 2;
printf(“删除位置%d上的节点\n“ i);
Sleep(500);
int tempi = 1;
Pointlist p; //p为查找结点。
p = head;
while (tempi != i && p != NULL)
{
p = p->next;
tempi++;
}
if (p == NUL
- 上一篇:中文邮件语料库.docx
- 下一篇:fme 2012的licgen.exe
相关资源
- 稀疏矩阵的十字链表表示方法:矩阵
- 串的基本操作定长顺序存储表示:初
- 在LPC2368上实现的FFT程序功率
- 基于单片机的串口多机通信6机
- 流水灯实验报告
- 数据结构与算法教学大纲程序代码
- 汽车控制系统
- GPS公交自动报站
- 三角函数包括反三角函数不调用库实
- RC4 加密算法 C演示代码
- STC12C2052AD的参考例程
- Malloc和mfree函数的实现原理
- ledkey.dll simboard.dll
- 51核心 自制鼠标 PS2协议 PAN3401光学芯
- Lsd基于TCP实现聊天系统
- 广工数据结构anyview2019最新完整参考答
- C笔试面试题及答案解析(一)
- 汽车加油问题 动态规划
- C典型题目1.输入一个5行5列的二维数组
- MB85RC64驱动
- 基于STM32的FFT变换
- MISRA C 2012英文版
- GCC编译器官方文档
- 谭浩强C程序设计完整ppt和程序第五版
- freeswitch的esl控制方式demo
- STM3210x_md.s启动文件
- linux下从公钥指数Exponent和模数Modulu
- 哈夫曼编解码器.zip
- 蚁群算法解决TSP问题的C实现代码直接
- WAV转换为C代码的小工具
评论
共有 条评论