📄 test1.cpp
字号:
// test1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
struct llist{
int data;
struct llist *next;
};
typedef struct llist node;
typedef node* llink;
llink createlist(){
llink s,r,temp;
int x;
s=(llink)malloc(sizeof(node));
printf("输入数据==>\n");
scanf("%d",&x);
s->data=x;
s->next=NULL;
r=s;
while (x!=0)
{
temp=(llink)malloc(sizeof(node));
printf("输入数据==>\n");
scanf("%d",&x);
temp->data=x;
temp->next=NULL;
r->next=temp;
r=temp;
}
return s;
}
llink cha(llink a,llink b){
llink ptr1,ptr2,par;
int f=0;
par=a;
ptr1=a;
while (ptr1!=NULL)
{ptr2=b;
while (ptr2!=NULL)
{
if (ptr2->data==ptr1->data)
{
if (ptr1==a)
{a=a->next;
ptr1=a;
par=a;
}
else{
par->next=par->next->next;
ptr1=par->next;
f=1;
break;
}
}
else{
ptr2=ptr2->next;
}
}
if(f==0){
par=ptr1;
ptr1=ptr1->next;}
}
return a;
}
int main(int argc, char* argv[])
{
llink a,b,c,ptr;
a=createlist();
b=createlist();
c=cha(a,b);
ptr=c;
printf("两集合的差是:\n");
while (ptr!=NULL)
{
printf("%d\n",ptr->data);
ptr=ptr->next;
}
printf("\n");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -