#include <iostream>
using namespace std;
struct Node
{
int data;
Node *next;
};
class link
{
private:
Node *start,*tail;
public:
link()
{
start=NULL;
tail=NULL;
}
void add(int a)
{
struct Node*nn=(struct Node*)malloc(sizeof(struct Node));
nn->data=a;
nn->next=NULL;
if(start==NULL)
{
start=nn;
tail=nn;
}
else
{
tail->next=nn;
tail=tail->next;
}
}
void print(int p,int n)
{
int c=p-n;
cout<<"Linked List : ";
while(start!=NULL)
{
while(c>0)
{
cout<<"->"<<(start->data);
start=start->next;
c--;
}
break;
}
}
};
int main() {
//cout<<"Hello World";
int n,p,d;
link ob;
cin>>n;
for(int x=0;x<n;x++)
{
cin>>p;
ob.add(p);
}
cin>>d;
ob.print(n,d);
return 0;
}
using namespace std;
struct Node
{
int data;
Node *next;
};
class link
{
private:
Node *start,*tail;
public:
link()
{
start=NULL;
tail=NULL;
}
void add(int a)
{
struct Node*nn=(struct Node*)malloc(sizeof(struct Node));
nn->data=a;
nn->next=NULL;
if(start==NULL)
{
start=nn;
tail=nn;
}
else
{
tail->next=nn;
tail=tail->next;
}
}
void print(int p,int n)
{
int c=p-n;
cout<<"Linked List : ";
while(start!=NULL)
{
while(c>0)
{
cout<<"->"<<(start->data);
start=start->next;
c--;
}
break;
}
}
};
int main() {
//cout<<"Hello World";
int n,p,d;
link ob;
cin>>n;
for(int x=0;x<n;x++)
{
cin>>p;
ob.add(p);
}
cin>>d;
ob.print(n,d);
return 0;
}
No comments:
Post a Comment