Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int insert(list *mylist, char x, unsigned int pos) // добавить после n-ного элемента
- {
- link* temp=malloc(sizeof(link));
- if(pos==0) // нулевой элемент не существует, считаем что это перед begin
- {
- if((mylist->begin)==NULL) {
- mylist->current=malloc(sizeof(link));
- mylist->begin=malloc(sizeof(link));
- temp->next=NULL;
- }
- else { temp->next=mylist->begin; }
- temp->value=x;
- mylist->begin=temp;
- mylist->current=mylist->begin;
- }
- else{
- if(getByPos(mylist, pos)==INT_MAX) return -1;
- temp->value=x;
- temp->next=mylist->current->next;
- mylist->current->next=temp;
- mylist->current=temp;
- }
- return 0;
- // current будет указывать на добавленный элемент
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement