Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct elem
- {
- int info;
- elem *next;
- };
- elem *insert_begin(elem *ptr, int a);
- void print(elem *ptr);
- elem *vvod(elem *ptr);
- void udalenie(elem *ptr);
- elem *insert_end(elem *ptr, int a);
- int main()
- {
- setlocale(LC_ALL, "Russian");
- elem *head;
- head=new elem;
- head->next=NULL;
- head=vvod(head);
- udalenie(head);
- cout<<"NEW LIST"<<endl;
- print(head->next);
- system("pause");
- return 0;
- }
- elem *vvod(elem *ptr)
- {
- int a;
- cout<<"Введите элементы списка "<<endl;
- cin>>a;
- while (a)
- {
- //ptr=insert_begin(ptr,a);
- ptr=insert_end(ptr,a);
- cin>>a;
- }
- return ptr;
- }
- void udalenie(elem *ptr){
- elem *ptr2=ptr;
- while(ptr2->next!=NULL)
- {
- if(ptr2->info==ptr2->next->info){
- free(ptr2);
- ptr2=NULL;
- free(ptr2);
- ptr2=ptr2->next->next;
- cout<<ptr2->info<<" qweqwewqewqeqwewq"<<endl;
- }
- else ptr2=ptr2->next;
- }
- }
- elem *insert_begin(elem *ptr, int a)
- {
- elem *temp;
- temp=new elem;
- temp->info=a;
- temp->next=ptr;
- return temp;
- }
- elem *insert_end(elem *ptr, int a)
- {
- elem *ptr2;
- ptr2=ptr;
- while (ptr2->next != NULL)
- ptr2=ptr2->next;
- elem *temp;
- temp=new elem;
- temp->info=a;
- temp->next=NULL;
- ptr2->next=temp;
- return ptr;
- }
- void print(elem *ptr)
- {
- elem *temp;
- temp=ptr;
- while (temp!=NULL)
- {
- cout<<temp->info<<" ";
- temp=temp->next;
- }
- cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement