Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TAHMID RAHMAN
- DAMIAN FOREVER
- MATH LOVER
- NEVER GIVE UP
- */
- #include<bits/stdc++.h>
- using namespace std;
- #define pi acos(-1.0)
- #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- #define ll long long
- #define pb push_back
- #define fi first
- #define se second
- #define in insert
- #define mp make_pair
- #define GCD(a,b) __gcd(a,b);
- #define endl "\n"
- #define FRU freopen("out.txt","w",stdout)
- #define FRO freopen("in.txt","r",stdin)
- #define INFLL 9223372036854775807
- #define debug 0
- #define MAXN 100001
- #define ar array
- const int mxN=2e5;
- const int MOD=1e9+7;
- bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
- //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
- struct node
- {
- int data;
- struct node* next;
- };
- struct node* head=NULL;
- struct node* cur=NULL;
- void SUM(int n)
- {
- struct node* temp=head;
- while(temp!=NULL)
- {
- temp->data+=n;
- temp=temp->next;
- }
- }
- void in_sert(int n,int data)
- {
- struct node* temp=(struct node*)malloc(sizeof(struct node));
- temp->data=data;
- temp->next=NULL;
- if(n==1)
- {
- temp->next=head;
- head=temp;
- return;
- }
- struct node* temp1=head;
- for(int i=0;i<n-2;i++)
- {
- temp1=temp1->next;
- }
- temp->next=temp1->next;
- temp1->next=temp;
- }
- void dele_te(int n)
- {
- struct node* tempx=head;
- if(n==1)
- {
- head=tempx->next;
- free(tempx);
- return ;
- }
- int i;
- for(i=0;i<n-2;i++)
- {
- tempx=tempx->next;
- }
- struct node* tempxx=tempx->next;
- tempx->next=tempxx->next;
- free(tempxx);
- }
- int length()
- {
- ll len=0;
- struct node*p=head;
- while(p!=NULL)
- {
- len++;
- p=p->next;
- }
- return len;
- }
- void print()
- {
- struct node* ptr=head;
- while(ptr!=NULL)
- {
- printf("%d ",ptr->data);
- ptr=ptr->next;
- }
- }
- bool isempty()
- {
- return (head==NULL);
- }
- int main()
- {
- ll t;
- cin>>t;
- while(t--)
- {
- string s,p="P",d="D",u="U";
- int n,m;
- cin>>s;
- if(s==d)
- {
- cin>>n;
- ll x=length();
- if(x<n||x==0)
- {
- cout<<"There is no such node."<<endl;
- }
- else
- dele_te(n);
- }
- else if(s==p)
- {
- if(isempty()==1)
- cout<<"The linked list is empty."<<endl;
- else
- print();
- cout<<endl;
- }
- else if(s==u)
- {
- cin>>n;
- SUM(n);
- }
- else
- {
- cin>>n>>m;
- ll xx=length();
- if(xx+1<n)
- cout<<"There is no such node."<<endl;
- else
- in_sert(n,m);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement