Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node{
- int val;
- node *next;
- };
- void _CreateList ( node *&first);//tworzy listê
- void _CoutList (node *first);//wypisuje listê
- int _ListLength (node *first);//zwraca d³ugoœæ listy
- void Insert (node *&head, int val){
- if(head==NULL){//jeśli lista jest pusta
- head=new node;
- head->val=val;
- head->next=NULL;
- return;
- }
- node *prev=NULL;
- node *cur=head;
- node *tmp=new node;
- tmp->val=val;
- tmp->next=NULL;
- if(head->val > val) {//wstawianie na początek
- tmp->next=head;
- head=tmp;
- return;
- }
- while (cur != NULL && cur->val < val){
- prev=cur;
- cur=cur->next;
- }
- if(cur!=NULL && val == cur->val) return;
- else {
- prev->next=tmp;
- tmp->next=cur;
- }
- }
- int FindDistinct (int *A, int n){
- int res;
- node *list=NULL;
- for(int i=0;i<n;i++){
- Insert(list,abs(A[i]));
- }
- res=_ListLength(list);
- return res;
- }
- int main()
- {
- int n;
- cin>>n;
- int A[n];
- for(int i=0;i<n;i++) cin>>A[i];
- cout<<FindDistinct(A,n);
- return 0;
- }
- int _ListLength(node *first){
- int length=0;
- while (first!=NULL){
- length++;
- first=first->next;
- }
- return length;
- }
- void _CreateList ( node *&first){
- int len;
- cin>>len;
- node *p;
- for(int i=0;i<len;i++){
- int x;
- cin>>x;
- p= new node;
- p->val=x;
- p->next=first;
- first=p;
- }
- }
- void _CoutList (node *first){
- while ( first !=NULL)
- {
- cout<<first->val<<" ";
- first=first->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement