概述
#include
#include
#include
#define MAXSIZE 100
#define DATA_TYPE int
typedef struct
{
DATA_TYPE data[MAXSIZE];
int length;
}SeqList;
SeqList initData(); //初始化数据
void output(SeqList list); //输出数据
int SeqList_Locate_e(SeqList *list, DATA_TYPE data, int pos); //定位重复的数据
int SeqList_Delete(SeqList *list, int pos); //删除数据
int main(void)
{
int i = 0, pos = 0;
SeqList list = initData();
printf("noriginal datan");
output(list);
for (i = 0; i < list.length; i++)
{
do
{
pos = SeqList_Locate_e(&list, list.data[i], i);
SeqList_Delete(&list, pos);
} while(pos < list.length && pos != -1);
}
printf("nresult data:n");
output(list);
printf("n");
return 0;
}
SeqList initData()
{
SeqList list;
int i = 0;
list.length = 0;
srand((unsigned) time(NULL));
for (i = 0; i< 10; i++)
{
list.length++;
list.data[i] = rand() % 20 + 10;
}
return list;
}
void output(SeqList list)
{
int i = 0;
for (i = 0; i < list.length; i++)
{
if ((i+1) % 5 == 0)
{
printf("%dn", list.data[i]);
}
else
{
printf("%dt", list.data[i]);
}
}
}
int SeqList_Locate_e(SeqList *list, DATA_TYPE data, int pos)
{
int i = pos + 1;
while (i < list->length && (*list).data[i] != data)
{
i++;
}
if (i == list->length)
{
return -1;
}
else
{
return i;
}
}
int SeqList_Delete(SeqList *list, int pos)
{
int i = pos;
if (pos < 0 || pos > list->length)
{
return -1;
}
for (i = pos; i < list->length; i++)
{
list->data[i]= list->data[i+1];
}
list->length --;
return 0;
}
最后
以上就是还单身钢笔为你收集整理的删除数据中任何一个数c语言,产生N个随机数字,删除其中重复的数据(C语言实现)...的全部内容,希望文章能够帮你解决删除数据中任何一个数c语言,产生N个随机数字,删除其中重复的数据(C语言实现)...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复