LinkList
Link List
Threshold
Linked List
#include<iostream> using namespace std; struct node { int data; struct node *next; }; struct node *insert(struct node*); struct node *split(struct node*,int,int); void disp(struct node []); int counter,counter2=0; struct node *startn=NULL; int main() { struct node *start=NULL; char chh; do{ cout<<"1:"<<"\t"<<"Insert"<<endl; cout<<"2:"<<"\t"<<"split"<<endl; cout<<"3:"<<"\t"<<"Display"<<endl; int ch; cin>>ch; switch(ch) { case 1: start = insert(start); break; case 2: int th; cout<<counter; cout<<"Enter the threshold value"<<endl; cin>>th; startn=split(start,th,counter); for(int i=0;i<10;i++) { cout<<startn<<endl; startn++; } break; case 3: disp(startn); break; default: cout<<"Enter proper choice"<<endl; } cout<<endl<<"Do you want to continue"<<endl; cin>>chh; }while(chh=='Y' || chh=='y'); } struct node *insert(struct node *start) { int n; struct node *new_node=new struct node(); cout<<"Enter the data"<<endl; cin>>new_node->data; if(start==NULL) { new_node->next=NULL; start=new_node; counter=1; } else { new_node->next=start; start=new_node; counter=counter+1; } cout<<"count is "<<counter; return(start); } struct node *split(struct node *start,int th,int counter) { cout<<endl<<"SPLIT CALLED"<<endl; int tempval;struct node *temp=NULL; struct node *prev=NULL; struct node *Head1=start; struct node *Head2=NULL; if(th<counter)> { tempval=counter/2; temp=start;int i=0; Head1=start; startn=Head1; while (i<tempval)> { prev=temp; temp=temp->next;i++; } Head2=temp; prev->next=NULL; split(Head1,th,tempval); split(Head2,th,tempval); startn++; counter2++; cout<<endl<<counter2; } return(startn); } void display(struct node startn[]) { for(int i=counter2;i>0;i++) { cout<<endl<<"count"<<endl; struct node *temp=NULL; temp=startn; while(temp->next!=NULL) { cout<<temp->data; temp=temp->next; } startn--; } /*while(counter2!=0) { struct node *temp=startn; while(temp!=NULL) { cout<<temp->data; temp=temp->next; } counter2--; } */ }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)