Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
doubly
# include <iostream> using namespace std; class Node { public: int data; Node* next; Node* prev; }; void add_first(Node* &head,int new_data){ Node*new_node = new Node(); new_node->data=new_data; new_node->next=head; new_node->prev=NULL; head = new_node; } void add_end(Node* &head,int new_data){ Node* new_node =new Node(); new_node->data=new_data; Node*temp=head; while(temp->next!=NULL){ temp=temp->next; } temp->next=new_node; new_node->prev=temp; } void add_pos(Node* &head, int pos ,int new_data){ if(pos==1){ cout<<"call another function"<<endl; return; } int i=1; Node* new_node =new Node(); new_node->data=new_data; Node* temp=head; while (i<pos-1) { temp=temp->next; i++; } new_node->next=temp->next; new_node->prev=temp; temp->next=new_node; temp=temp->next; temp->prev=new_node; } void del_key(Node* &head,int key){ if(head->data==key){ head=head->next; return; } Node*temp1=head; Node*temp2=head; while(temp1->data!=key){ temp2=temp1; temp1=temp1->next; } temp2->next=temp1->next; temp1=temp1->next; temp1->prev=temp2; } void disp(Node* head){ int cnt=0; while(head!=NULL){ cout<<" "<<head->data; head=head->next; cnt++; } cout<<endl<<"the length of linked list is "<<cnt; } void reverse_list(Node* &head){ Node*curr; Node*nxt; Node*prev; curr=head; while(curr!=NULL){ nxt=curr->next; curr->next=curr->prev; curr->prev=nxt; prev=curr; curr=nxt; } head=prev; } int main(){ Node*head=NULL; add_first(head,7); add_first(head,8); add_first(head,9); add_first(head,0); add_end(head,1); add_end(head,2); add_pos(head,2,4); del_key(head,0); reverse_list(head); cout<<"the linked list is "; disp(head); return 0; }
run
|
edit
|
history
|
help
0
cppPyEnum
swastic
Q
SFML ANIMATOR
next permutation leetcode
Print reverese string non repeated chars
Aplicatie-Proiect
LIS
stl_sizeof
19 მარტს დამუშავებული