
15.11.2008, 14:19
|
|
Участник форума
Регистрация: 31.10.2007
Сообщений: 213
Провел на форуме: 394522
Репутация:
14
|
|
Народ помогите доделать/исправить :
Во общем нужно :
1 - создать список целых значений
2- каждое новое значение должно входить в список только если раньше не встречалось !
3 - вывести список на екран !
У меня список создаетса , выводитса , но вот проверка на повторяемость не получается (она в программе закоментирована ) если ее раскоментировать то программа не работает ! Подскажите как организовать проверку ...
Код:
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <ctype.h>
# include <conio.h>
# include <iostream.h>
#define MAX 100
typedef struct {
int elements[MAX];
int count;
} listtype;
void list_reset(listtype *list) {
list->elements[0]=0;
list->count=0;
}
void list_add(listtype *list,int element)
{
/* for(int i=0 ; i<list->count;i++)
{
if(list->elements[i] == element)
{
printf("Element [%i] is consist ! Input other el !",element);
getch();
}
else{*/
if (list->count != MAX)
list->elements[list->count++]=element;
//}
//}
}
void list_print(listtype *list){
int i;
for(i = 0;i < list->count;i++)
{
printf("Element[%i] = %i\n",i+1,list->elements[i]);
}
}
void main ()
{
clrscr();
listtype list;
int el;
list_reset(&list);
char c;
int K;
cout <<"Input First El :";cin>>el;
list_add(&list,el);
cout <<"\nAdd El ? [Y/N]";cin>>c;
while (c == 'Y' || c == 'y')
{
cout <<"\nInput El:";cin>>el;
list_add(&list,el);
cout <<"\nAdd El ? [Y/N]";cin>>c;
}
cout <<"\nPrint List ?[Y/N]";cin>>c;
if(c == 'Y' || c == 'y')
{
list_print(&list);
getch();
}
getchar();
}
|
|
|