1.顺序表和链表综合
//在递增有序的顺序表中编程实现A=A-B∩C
//在递增有序的顺序表中编程实现A=A-B∩C
typedef int ElemType;
#include "sqlist.h"//即为数据结构(一)顺序表部分
#include<stdlib.h>
int main()
{
SqList mylist1,mylist2,mylist3;
/*��ʼ��˳����L*/
initlist(mylist1);
initlist(mylist2);
initlist(mylist3);
/*����˳����L*/
mycreat(mylist1);
mycreat(mylist2);
mycreat(mylist3);
int i = 0, j = 0, k = 0;
for (i = 0;i < mylist1.length;i++)
{
int m = mylist1.elem[i];
for (j = 0;j < mylist2.length;j++)
{
int n = mylist2.elem[j];
if (m == n)
{
for (k = 0;k < mylist3.length;k++)
{
int t = mylist3.elem[k];
if (t == n)
{
mylistdelete(mylist1, i);
i--;
}
else
continue;
}
}
else
continue;
}
}
output(mylist1);
system("pause");
return 0;
}
//
编程实现在有序的单链表结构中删除表中所有值大于mink且小于maxk的元素(mink<=maxk)
#include<stdio.h>
#include"linklist.h"//即为数据结构(一)的链表部分
#include<stdlib.h>
void main()
{
Linklist myLinklist,p, t;
initlist(myLinklist);
creat(myLinklist);
p=t = myLinklist;
myLinklist = t->next;
int maxk = 10, mink = 1;
while (myLinklist!= NULL)
{
if (myLinklist->data > maxk)
return;
if (myLinklist->data <= mink)
{
t = myLinklist;
myLinklist = myLinklist->next;
}
else
{
t->next = myLinklist->next;
myLinklist = t->next;
}
}
output(p);
system("pause");
}
2.栈
应用栈实现判定一个字符串中括号是否匹配(包括()、[ ]、{ })
/*
typedef Bitree SElemType;
typedef struct
{SElemType *base,*top;
int stacksize;
}Sqstack;
//初始化栈
void Initstack(Sqstack &s)
{ if((s.base=(SElemType *)malloc(100*sizeof(SElemType)))==NULL)
{ printf(" no size");
exit(0);
}
else {s.top=s.base;
s.stacksize=100;
}
}
//取出栈顶元素
SElemType Gettop(Sqstack s)
{ SElemType e;
e=*(s.top-1);
return e;
}
//删除栈顶元素,并用e返回
Status Pop(Sqstack &s,SElemType &e)
{ if(s.top==s.base) return ERROR;
s.top--;
e=*s.top;
return OK;
}
//将元素e压入栈中
Status Push(Sqstack &s,SElemType e)
{ if(s.top-s.base==s.stacksize) return ERROR;
*s.top=e;
s.top++;
return OK;
}
//判断栈是否为空
int Emptystack(Sqstack s)
{if(s.top==s.base)
return 1;
else return 0;
}*/
typedef char SElemType;#include "confere.h"#include "sqstack.h"//即为上文中/* */内部分#include<string.h>#define N 25Status judge(char ch1, char ch2){if (ch1 == '['&&ch2 == ']' || ch1 == '(' && ch2 == ')' || ch1 == '{'&&ch2 == '}')return OK;elsereturn FALSE;}void mychange2(Sqstack &S, char t){char c=0;if(!Emptystack(S)){
if (judge(Gettop(S), t)){
Pop(S, c);}
elsePush(S, t);return;}
Push(S, t);}void main(){Sqstack sq;sq.base=(SElemType*)malloc(sizeof(SElemType)*100);sq.top=sq.base;sq.stacksize=100;char buff[N] = { 0 };gets(buff);
int n = strlen(buff);for (int i = 0;i <n;i++){
mychange2(sq, buff[i]);}
char e = 0;while (!Emptystack(sq)){
Pop(sq, e);putchar(e);
}
}
注:上述代码作者自己书写,难免会有错误不足之处,欢迎读者指出,大家共同学习
![大笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)