The Programming Project: list
Showing posts with label list. Show all posts
Showing posts with label list. Show all posts

Saturday, October 12, 2013

GAME

The following program implements all features of Data Structures STACK, QUEUE and LIST using generic functions (templates in C++). User have choice for selection the data type float,integer or character to use the data structures. Also there is a game which takes 3 positive integers as input a,b and c. a represent the number of digits, b represent the maximum sum of digits and c represent the maximum total sum of all the numbers formed during the game. The score of the game is the highest number formed. The user after inputting the parameters will sequentially enter the digits, and the game will automatically stops when the sum of the numbers formed exceeds c. For example is user enter 3,13,200 as parameters and the digits entered sequentially is 1,1,9,5,9,6,5,4, 8,9.... the numbers that will be stored in the stack will be 119,5,9,11,12,9.... using the restrictions.  The stack is then sorted using another stack and the top element is your score. The Game is generalized for decimal numbers also i.e., input can be 1,1,.,9,5,.9,...... so on.
Here is an sample output:





































Here is the link for the code http://sdrv.ms/16Wrw8x

 C++ Code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
#define TRUE 1
#define FALSE 0
void f1(void);
void f2(void);
void f3(void);
void f4(void);
template <class L> class List
    {
    private:
    L d;
    L *data;
    int i;
    public:
    List(){}
    List (int n)
        {
        data=new L[n];
        i=0;
        }
    void store()
        {
        cin>>d;
        data[i]=d;
        i++;
        }
    void display(int n)
        {
        for(i=0;i<n;i++)
            cout<<"\t"<<data[i];
        }
    };
template <class L>
class Stack: virtual public List<L>
    {
    protected:
    L *data;
    int top;
    public:
    Stack(){}
    Stack (int n)
    {
    data=new L[n];
    top=-1;
    }
    //static int t;
    void push(L,int);
    void pop(int *pund,L *x);
    };
//template<class L>int Stack::t=-1;
template<class L>
void Stack<L>::push(L x,int STACKSIZE)
    {
     if(top==STACKSIZE-1)
        {
        cout<<"\n Stack is full, element not inserted:";
        return;
        }
     else
     data[++top]=x;
     }
template<class L>
void Stack<L>::pop(int *pund, L *x)
    {
    if(top==-1)
        {
            *pund=TRUE;
            return;
        }
    else
        {
        *x=data[top--];
        *pund=FALSE;
        return;
        }
    }
template<class L>
class Queue: virtual public List<L>
    {
    protected:
    L *data;
    int front;
    int rear;
    public:
    Queue(){}
    Queue(int MAXQUEUE)
        {
        data=new L[MAXQUEUE];
        front=rear=MAXQUEUE-1;
        }
    void insert(int MAXQUEUE,L x);
    void remove(L *x,int *pund,int MAXQUEUE);
    };
template<class L>
void Queue<L>::remove(L *x,int *pund,int MAXQUEUE)
    {
        if(rear==front)
            {
            cout<<"\n Queue is empty:";
            *pund=TRUE;
            return;
            }
        if(front==MAXQUEUE-1)
            front=0;
        else
            front++;
        *x=data[front];
        return;
    }
template<class L>
void Queue<L>::insert(int MAXQUEUE,L x)
    {
    if(rear==MAXQUEUE-1)
        rear=0;
    else
        rear++;
    if(rear==front)
        {
        cout<<"\n Queue overflow, element not inserted:";
        return;
        }
    data[rear]=x;
      return;
    }
template<class L>
class GAME:public Stack<L>,public Queue<L>
    {
    protected:
    L *digits;
       int tdigits;
    L dsum;
    L tsum;
    public:
    GAME(int a,int b,int c)
        { tdigits=a; dsum=b; tsum=c; }
    GAME():Stack<L>(400),Queue<L>(400)
        { digits= new L[400]; }
    void enter_digits(GAME,GAME,bool);
    };
template<class L>
void GAME<L>::enter_digits(GAME s2,GAME s3,bool FLAG)
{
    int und,pund=FALSE,len,k;
    int i=0,j=0,FLAG1=TRUE,dg=0,DFLAG=0,DCOUNT,count=0;
    L y,x,a,numb=0,sumd=0,tmp=0,sumt=0,numb1=0;
    char t[10],dot[3];
    if(FLAG)
    {
    do
    {

        for(i=0;i<tdigits;i++)
            {
          
            cout<<"\n Enter a digit: ";
            cin>>t;
            len=strlen(t);
            if(!atoi(t) && atoi(t) != 0)
                {
                i--;
                cout<<"\n You must enter a digit:\n";
                continue;
                }
            if(len>1)
                {
                i--;
                cout<<"\n You must enter a digit:\n";
                continue;
                }
            a=atoi(t);
            s2.insert(400,a);
            }
        do  
            {
                 if(sumd>dsum)
                break;
            else
                {
                if(FLAG1==TRUE)
                            numb=tmp+numb*10;
                s2.remove(&x,&und,400);
                    numb=x+numb*10;
                sumd=sumd+x;
                if(sumd>dsum)
                    {
                    tmp=x;
                    FLAG1=TRUE;
                    sumd -=x;
                     break;
                    }
                tmp=0;
                }
            FLAG1=FALSE;
            j++;
            }while(j<tdigits);
         if(FLAG1==TRUE)
         {j=1;numb=numb/10;}
         else
         {j=0;}
         //cout<<"\n <Number>"<<numb;
         s2.pop(&pund,&y);
             if(pund==TRUE)
            s2.push(numb,400);
            else
               {
               if(numb>=y)
                   {
                   s2.push(y,400);
                   s2.push(numb,400);
                   }
               else
                   {
                   s3.push(y,400);
                       while(y>numb)
                       {
                       s2.pop(&pund,&y);
                       if(pund==TRUE || y<=numb)
                           {
                           if(pund==TRUE)
                           {break;}
                           else
                           {s2.push(y,400); break;}
                           }
                       s3.push(y,400);
                        }
                        s2.push(numb,400);
                       while(1)
                       {
                       s3.pop(&pund,&y);
                       if(pund==TRUE)
                           break;
                       s2.push(y,400);
                       }
                  }
        }
        sumt +=numb;
        sumd=tmp;
        numb=0;

    }while(sumt<=tsum);
    s2.pop(&pund,&y);
    cout<<"\n Game ends,your score is:"<<y;
    cout<<"\n The sequence of numbers formed on the stack in descending order:\n";
    while(1)
    {
    cout<<y;
    s2.pop(&pund,&y);
    if(pund==TRUE)
        break;
    cout<<"\n";
    }
    }//end of integer game
    else
    {
        strcpy(dot,"$");
     do
        {
        for(i=0;i<tdigits;i++)
        {
        cout<<"\n Enter the number:";
        cin>>t;
         //cout<<strlen(t);
            if(strlen(t)>=2)
            {
                  cout<<"\n Not a valid input:";
            i--;
            continue;
            }
        if(strcmp(dot,t)==0)
            {
            i--;
            cout<<"\n Two consecutive dots not allowed:";
            continue;
            }
        if(strcmp(t,".")==0)
            {
            strcpy(dot,t);
            a=-1.0;
            s2.insert(400,a);
            continue;
            }
        if(!atof(t) || !atoi(t))
            {
                  cout<<"\n Not a valid input:";
            i--;
            continue;
            }
            j=0;
        while(t[j]!='\0' && strlen(t)<2)
              {  
              a=atof(t);
              s2.insert(400,a);
                j++;
                        }
                strcpy(dot,"$");
          } //end of one set of input
          und=TRUE;
           while(und)
             {
             s2.remove(&x,&und,400);
             if(x==-1)
                 {
                 DCOUNT++;
                 DFLAG=TRUE;
                 j=1;
                 if(DCOUNT==2)
                     break;
                 }//end of if
             else
                 {
                 if(DFLAG==TRUE)
                     {
                     sumd +=x;
                     if(sumd>dsum)
                         {
                         tmp=x;
                         DFLAG=FALSE;
                         break;
                         }
                     count++;
                     numb1=numb1+x*pow(10,-j);
                     j++;
                     if(count==tdigits)
                     break;
                     }//end of if
                 else
                     {
                     sumd +=x;
                     if(sumd>dsum)
                         {
                         tmp=x;
                         break;
                         }
                     count++;
                     numb=x+numb*10;
                     }//end of inner else
                 if(count==tdigits)
                 break;
                 }//end of else
             cout<<"\n Sumd="<<sumd;
             cout<<"\n Count="<<count;
             cout<<"\n J="<<j;
             cout<<"\n DFLAG="<<DFLAG;
             } //end of while(und)  
    count=0;
    numb=numb+numb1;
    cout<<"\n <Number>\n"<<numb;
    sumt +=numb;
    numb=0.0;
    numb1=0.0;
    if(DFLAG==TRUE && tmp!=0)
        {
        count++;
        numb1=numb1+tmp*pow(10,-j);
        sumd=tmp;
        }
    if(DFLAG==FALSE && tmp!=0)
        {
        count++;
        numb=tmp+numb*10;
        sumd=tmp;
        }
    }while(sumt<70.0);    
    }//end of float game
}
int main()
{
    int menu;
    cout<<"\n Press '1' for LIST:";
    cout<<"\n Press '2' for STACK:";
    cout<<"\n Press '3' for QUEUE:";
    cout<<"\n Press '4' to play the GAME:";
    cout<<"\n Press '5' to exit:";
    do{
    cout<<"\n Enter your choice:";
    cin>>menu;
    switch(menu)
        {
        case 1:
        f1();
        break;
        case 2:
        f2();
        break;
        case 3:
        f3();
        break;
        case 4:
        f4();
               break;
        default:
        break;
        }
    }while(menu!=5);
return 0;
}
void f4(void)
{
    int a,b,c,ch;
    bool FLAG;
    cout<<"\n Enter the values of a,b and c to begin:";
    cin>>a>>b>>c;
    GAME <int>s1(a,b,c); GAME<int>s2;GAME <int>s3;
    GAME <float>t1(a,b,c); GAME <float>t2; GAME <float>t3;
    cout<<"\n Enter 1 to play with positive digits:";
    cout<<"\n Enter 2 to play with floating point:";
    cout<<"\n Enter your choice:";
    cin>>ch;
    if(ch==1)
        {
        FLAG=1;
        cout<<"\n Start entering digits:\n";
        s1.enter_digits(s2,s3,FLAG);
        }
    if(ch==2)
        {
        FLAG=0;
        cout<<"\n Start entering digits:\n";
        t1.enter_digits(t2,t3,FLAG);
        }
  
   
}
void f3(void)
{
    int n,choice,x,und,ch;
    Queue <int>Q1(n);
    Queue <float>Q2(n);
    float x1;
    cout<<"\n Enter the size of the QUEUE:";
    cin>>n;
    cout<<"\n Enter 1 to add integer values to QUEUE:";
    cout<<"\n Enter 2 to add floating point values to QUEUE:";
    cout<<"\n Enter your choice:";
    cin>>ch;
    if(ch==1)
    {
    cout<<"\n Press 1 to insert an element in the Queue:";
    cout<<"\n Press 2 to remove an element from the Queue:";
    cout<<"\n Press 3 to exit:";
    do
    {
    cout<<"\n Enter your choice for menu:";
    cin>>choice;
    switch(choice)
        {
        case 1:
        cout<<"\n Enter the element:";
        cin>>x;
        Q1.insert(n,x);
        break;
        case 2:
        Q1.remove(&x,&und,n);
        if(und==TRUE)
            {
          //    cout<<"\n Queue Underflow:";
            break;
            }
        else
        cout<<"\n Element removed is:  "<<x;
        break;
        default:
        break;
        }
    } while(choice!=3);
    }
    if(ch==2)
    {
    cout<<"\n Press 1 to insert an element in the Queue:";
    cout<<"\n Press 2 to remove an element from the Queue:";
    cout<<"\n Press 3 to exit:";
    do
    {
    cout<<"\n Enter your choice for menu:";
    cin>>choice;
    switch(choice)
        {
        case 1:
        cout<<"\n Enter the element:";
        cin>>x;
        Q2.insert(n,x1);
        break;
        case 2:
        Q2.remove(&x1,&und,n);
        if(und==TRUE)
            {
          //    cout<<"\n Queue Underflow:";
            break;
            }
        else
        cout<<"\n Element removed is:  "<<x1;
        break;
        default:
        break;
        }
    } while(choice!=3);
    }
  
}
void f2(void)
{
    int n,choice,x,und,ch;
    Stack <int>S1(n);
    Stack <float>S2(n);
    float x1;
    cout<<"\n Enter the size of the STACK:"<<endl;
    cin>>n;
    cout<<"\n Enter 1 to add integer values to List:";
    cout<<"\n Enter 2 to add floating point values to List:";
    cout<<"\n Enter your choice:";
    cin>>ch;
    if(ch==1)
    {
    cout<<"\n Press 1 to push an element in the stack:";
    cout<<"\n Press 2 to pop an element:";
    cout<<"\n Press 3 to exit:";
    do
    {
    cout<<"\n Enter your choice for menu:";
    cin>>choice;
    switch(choice)
        {
        case 1:
        cout<<"\n Enter the element:";
        cin>>x;
        S1.push(x,n);
        break;
        case 2:
        S1.pop(&und,&x);
        if(und==TRUE)
            {
            cout<<"\n Stack Underflow:";
            break;
            }
        else
        cout<<"\n Element popped out is:  "<<x;
        break;
        default:
        break;
        }
    } while(choice!=3);
    }
    if(ch==2)
    {
    cout<<"\n Press 1 to push an element in the stack:";
    cout<<"\n Press 2 to pop an element:";
    cout<<"\n Press 3 to exit:";
    do
    {
    cout<<"\n Enter your choice for menu:";
    cin>>choice;
    switch(choice)
        {
        case 1:
        cout<<"\n Enter the element:";
        cin>>x1;
        S2.push(x1,n);
        break;
        case 2:
        S2.pop(&und,&x1);
        if(und==TRUE)
            {
            cout<<"\n Stack Underflow:";
            break;
            }
        else
        cout<<"\n Element popped out is:  "<<x1;
        break;
        default:
        break;
        }
    } while(choice!=3);
    }
}
void f1(void)
{
    int n,nf=0,choice;;
    char c;
    List <int> Ls(n);
    List <float>Ls1(n);
    List <char>Ls2(n);
    cout<<"\n Enter the number of elements to be stored in the list:"<<endl;
    cin>>n;
    cout<<"\n Enter 1 to add integer values to List:";
    cout<<"\n Enter 2 to add floating point values to List:";
    cout<<"\n Enter 3 to add character values to List:";
    cout<<"\n Enter your choice:";
    cin>>choice;
    if(choice==1)
        {
      
        do
    {
    cout<<"\n Enter the element in the list:";
    Ls.store();
    nf++;
    if(nf==n)
        {
        cout<<"\n No more elements can be added:";
        break;
        }
    cout<<"\n Do you wish to enter another element (y/n):";
    cin>>c;
    }while (c!='n');
    cout<<"\n Press 'v' to view the list or any other key to exit:";
    cin>>c;
     if(c=='v')
    Ls.display(nf);
        }
    if(choice==2)
        {
      
        do
    {
    cout<<"\n Enter the element in the list:";
    Ls1.store();
    nf++;
    if(nf==n)
        {
        cout<<"\n No more elements can be added:";
        break;
        }
    cout<<"\n Do you wish to enter another element (y/n):";
    cin>>c;
    }while (c!='n');
    cout<<"\n Press 'v' to view the list or any other key to exit:";
    cin>>c;
     if(c=='v')
    Ls1.display(nf);
        }
    if(choice==3)
    {
        List <char>Ls[n];
      
    do
    {
    cout<<"\n Enter the element in the list:";
    Ls2.store();
    nf++;
    if(nf==n)
        {
        cout<<"\n No more elements can be added:";
        break;
        }
    cout<<"\n Do you wish to enter another element (y/n):";
    cin>>c;
    }while (c!='n');
    cout<<"\n Press 'v' to view the list or any other key to exit:";
    cin>>c;
     if(c=='v')
    Ls2.display(nf);
    }
}



Wednesday, February 13, 2013

C Program #10

/* Circular Link List */

#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct circular_list
{
int d;
struct circular_list *next;
};
typedef struct circular_list node;
void create(node *);
void display(node *,node *);
node *search(node *,node *);
void insert(node *,node *);
void displaypos(node *,node *);
int main()
{
int choice;
node *root,*head,*tag;
root=(node *)malloc(sizeof(node));
head=root;
printf("\n ***********************MENU FOR LIST******************* \n");
printf("\n Press 1 to create:");
printf("\n Press 2 to display:");
printf("\n Press 3 to search:");
printf("\n Press 4 to insert");
printf("\n Press 5 to display with respect to an element in the list:");
printf("\n Press 6 to exit \n");
while(1)
{
printf("\n Enter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
create(root);
break;
case 2:
display(root,head);
break;
case 3:
tag=search(root,head);
if(tag==NULL)
printf("\n Element not found:\n");
else
printf("\n The element is %d",tag->d);
break;
case 4:
insert(root,head);
break;
case 5:
displaypos(root,head);
break;
case 6:
exit(0);
break;
default:
break;
}
}
return 0;
}
void create(node *record)
{
int n,i;
node *p;
p=record;
printf("\n Enter the number of elements to be added:");
scanf("%d",&n);
printf("\n Enter the elements:\n");
scanf("%d",&record->d);
for(i=1;i<=n-1;i++)
{
record->next=(node *)malloc(sizeof(node));
record=record->next;
scanf("%d",&record->d);
}
record->next=p;
return;
}
void display(node *record,node *head)
{
printf("\n List elements are:\n");
while(1)
{
printf(" %d ",record->d);
record=record->next;
if(record==head)
break;
}
return;
}
node *search(node *record,node *head)
{
display(record,head);
node *p;
int n,flag=0;
printf("\n Enter the item to be searched:");
scanf("%d",&n);
while(record->next!=NULL)
{
if(record->d==n)
{
flag=1;
p=record;
break;
}
record=record->next;
if(record==head)
          break;
}
if(flag==1)
return (p);
else
return (NULL);
}
void insert(node *record,node *head)
{
node *pos,*p,*temp;
printf("\n Search the element after which the item has to be inserted:");
pos=search(record,head);
if(pos==NULL)
{
printf("\n Element cannot be inserted:");
}
else
{
p=(node *)malloc(sizeof(node));
printf("\n Enter the item to be inserted:");
scanf("%d",&p->d);
temp=pos->next;
pos->next=p;
p->next=temp;
}

}
void displaypos(node *record,node *head)
{
node *tag,*p;
printf("\n Search the item w.r.t which the list will be displayed:");
tag=search(record,head);
if(tag==NULL)
{
printf("\n List Cannot be displayed:\n");
}
else
{
p=tag;
printf("\n List with respect to %d",tag->d);
while(tag->next!=p)
{
printf(" %d ",tag->next->d);
tag=tag->next;
}
}
return;
}

Thursday, January 3, 2013

C Program #8


A program to demonstrate different operation on list using array. 


#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
void menu(void);
void create(void);
void insert(int *a,int*);
void deletee(int *a,int*);
void merge(int *a,int*);
void split(int *a,int*);
void sort(int *a,int*);
void search(int *a,int*);
void append(int *a,int*);
int c=1;
int main()
{
int i,*list,*list_size,n;
printf("\n Enter the list size \n");
scanf("%d",&n);
list_size=&n;
list=(int *)malloc(n*sizeof(int));
printf("\n Enter the elements:\n");
for(i=0;i<n;i++)
scanf("%d",(list+i));
while(1)
{
int choice;
printf("\n ***********MENU FOR LIST*********** \n");
printf("\n Press 1 to inserte \n");
printf("\n Press 2 to delete \n");
printf("\n Press 3 to merge \n");
printf("\n Press 4 to split \n");
printf("\n Press 5 to sort \n");
printf("\n Press 6 to search \n");
printf("\n Press 7 to append \n");
printf("\n Press 8 to exit \n");
printf("\n Enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
insert(list,&n);
break;
case 2:
deletee(list,&n);
break;
case 3:
merge(list,&n);
break;
case 4:
split(list,&n);
break;
case 5:
sort(list,&n);
break;
case 6:
search(list,&n);
break;
case 7:
append(list,&n);
break;
case 8:
exit(0);
break;
default:
puts("Wrong choice");
break;
}
}
return 0;
}
void insert(int *list,int *list_size)
{
int item,pos,i;
printf("\n List before insertion \n");
for(i=0;i<*list_size;i++)
   printf("\t %d",list[i]);
printf("\n Enter the item to be inserted and position\n");
scanf("%d %d",&item,&pos);
if(pos>*list_size)
{
puts(" Item cannot be inserted");
}
else{
for(i=*list_size;i>pos-1;i--)
list[i]=list[i-1];
list[pos-1]=item;
*list_size+=1;
printf("\n List after insertion \n");
for(i=0;i<*list_size;i++)
printf("\t %d",list[i]);
}
return ;
}
void deletee(int *list,int *list_size)
{
int item,pos,flag=1,i;
printf("\n Enter the item to be deleted:\n");
scanf("%d",&item);
for(i=0;i<*list_size;i++)
{
if(item==list[i])
{
pos=i;
flag=1;
break;
}
else
flag=0;
}
if(flag==0)
printf("\n Item not found, cannot be deleted:\n");
else
{
printf("\n List before deletion \n");
for(i=0;i<*list_size;i++)
printf("\t %d",list[i]);
for(i=pos;i<*list_size;i++)
list[i]=list[i+1];
*list_size-=1;
printf("\n List after deletion \n");
for(i=0;i<*list_size;i++)
printf("\t %d",list[i]);
return ;
}
}
void merge(int *list,int *list_size)
{
int a[50],n,i;
printf("\n Enter the size of the list to be merged \n");
scanf("%d",&n);
printf("\n Enter the items of the new list:\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=*list_size;i<*list_size+n;i++)
list[i]=a[i-*list_size];
printf("\n List before merging \n");
for(i=0;i<*list_size;i++)
printf("\t %d",list[i]);
*list_size+=n;
printf("\n List after merging \n");
for(i=0;i<*list_size;i++)
printf("\t %d",list[i]);

return;
}
void split(int *list,int *list_size)
{
int b[25],i,j,pos;
printf("\n List items are: \n");
for(i=0;i<*list_size;i++)
printf("\t %d",list[i]);
printf("\n Enter the position at which the list will be splitted:\n");
scanf("%d",&pos);
printf("\n List after splitting:\n");
printf("\n List #1 \n");
for(i=pos;i<*list_size;i++)
{
b[i-pos]=list[i];
printf("\t %d",b[i-pos]);
}
printf("\n List #2 \n");
for(i=0;i<pos;i++)
printf("\t %d",list[i]);
*list_size=pos;
return;
}
void sort(int *list,int *list_size)
{
int i,temp,j;
printf("\n List before sorting \n");
for(i=0;i<*list_size;i++)
printf("\t %d",list[i]);
for(i=0;i<*list_size;i++)
{
for(j=i;j<=*list_size-1;j++)
{
if(list[i]<list[j])
{
temp=list[i];
list[i]=list[j];
list[j]=temp;
}
}
}
printf("\n List after sorting \n");
for(i=0;i<*list_size;i++)
printf("\t %d",list[i]);
return;
}
void search(int *list,int *list_size)
{
int item,flag=1,i,count=0,a[10];
printf("\n List items are: \n");
for(i=0;i<*list_size;i++)
printf("\t %d",list[i]);
printf("\n Enter the item to be searched:\n");
scanf("%d",&item);
for(i=0;i<*list_size;i++)
{
if(item==list[i])
{
a[count]=i;
count++;
flag=1;
continue;
}
else
flag=0;
}
if(flag==0 && count==0)
printf("\n Item not found:\n");
else
{
printf("\n Item %d is at postion",item);
for(i=0;i<count;i++)
printf("\t %d",a[i]+1);
}
return;
}
void append(int *list,int *list_size)
{
int item,pos,i;
printf("\n List items are: \n");
for(i=0;i<*list_size;i++)
printf("\t %d",list[i]);
printf("\n Enter the item to be appended & position:\n");
scanf("%d %d",&item,&pos);
if(pos>*list_size)
{
puts(" Item cannot be appended");
}
else{
list[pos-1]=item;
printf("\n List after appending: \n");
for(i=0;i<*list_size;i++)
printf("\t %d",list[i]);
      } 
return;
}

C Program #8


A program to demonstrate different operation on list using array. You might get unexpected output if two different operation is done on the list in the same run.
#include<stdio.h>
#include<stdlib.h>
void menu(void);
void create(void);
void insert(int a[],int);
void deletee(int a[],int);
void merge(int a[],int);
void split(int a[],int);
void sort(int a[],int);
void search(int a[],int);
void append(int a[],int);
int list[50],list_size,c=0;
int main()
{
menu();
return 0;
}
void menu(void)
{
while(1)
{
int choice;
printf("\n ***********MENU FOR LIST*********** \n");
printf("\n Press 0 to create \n");
printf("\n Press 1 to inserte \n");
printf("\n Press 2 to delete \n");
printf("\n Press 3 to merge \n");
printf("\n Press 4 to split \n");
printf("\n Press 5 to sort \n");
printf("\n Press 6 to search \n");
printf("\n Press 7 to append \n");
printf("\n Press 8 to exit \n");
printf("\n Enter your choice\n");
scanf("%d",&choice);
switch(choice)
     {
     case 0:
     create();
     break;
     case 1:
     insert(list,list_size);
     break;
     case 2:
     deletee(list,list_size);
     break;
     case 3:
     merge(list,list_size);
     break;
     case 4:
     split(list,list_size);
     break;
     case 5:
     sort(list,list_size);
     break;
     case 6:
     search(list,list_size);
     break;
     case 7:
   append(list,list_size);
     break;
     case 8:
     exit(0);
     break;
     default:
     puts("Wrong choice");
     break;
     }
}
return;
}
void split(int list[],int list_size)
{
     if(c==0)
          {
              puts(" LIST NOT CREATED, CREATE LIST FIRST ");
             
          }
     else{
     int b[25],i,j,pos;
   printf("\n List items are: \n");
     for(i=0;i<list_size;i++)
     printf("\t %d",list[i]);
     printf("\n Enter the position at which the list will be splitted:\n");
     scanf("%d",&pos);
   printf("\n List after splitting:\n");
     printf("\n List #1 \n");
     for(i=pos;i<list_size;i++)
          {
          b[i-pos]=list[i];
          printf("\t %d",b[i-pos]);
          }
     printf("\n List #2 \n");
     for(i=0;i<pos;i++)
     printf("\t %d",list[i]);
     list_size=list_size-pos;
   }
}
void create(void)
{
     c++;
   int i;
     printf("\n Enter the list size \n");
     scanf("%d",&list_size);
     printf("\n Enter the elements:\n");
     for(i=0;i<list_size;i++)
          scanf("%d",&list[i]);
}
void insert(int list[],int list_size)
{
     int item,pos,i;
   if(c==0)
          {
              puts(" LIST NOT CREATED, CREATE LIST FIRST ");
             
          }
     else{
     printf("\n Enter the item to be inserted and position\n");
     scanf("%d %d",&item,&pos);
     printf("\n List before insertion \n");
     for(i=0;i<list_size;i++)
          printf("\t %d",list[i]);
     for(i=list_size;i>pos-1;i--)
          list[i]=list[i-1];
          list[pos-1]=item;
     list_size+=1;
     printf("\n List after insertion \n");
     for(i=0;i<list_size;i++)
          printf("\t %d",list[i]);
     }
return ;
}
void deletee(int list[],int list_size)
{
     int item,pos,flag=1,i;
   if(c==0)
          {
              puts(" LIST NOT CREATED, CREATE LIST FIRST ");
             
          }
     else{
     printf("\n Enter the item to be deleted:\n");
     scanf("%d",&item);
     for(i=0;i<list_size;i++)
          {
              if(item==list[i])
                   {
                   pos=i;
                   flag=1;
                   break;
                   }
           else
           flag=0;
           }
     if(flag==0)
              printf("\n Item not found, cannot be deleted:\n");
     else
     {
     printf("\n List before deletion \n");
     for(i=0;i<list_size;i++)
          printf("\t %d",list[i]);
     for(i=pos;i<list_size;i++)
          list[i]=list[i+1];
          list_size-=1;
     printf("\n List after deletion \n");
     for(i=0;i<list_size;i++)
          printf("\t %d",list[i]);
     }
     return ;
     }
}
void merge(int list[],int list_size)
{
     int a[50],n,i;
   if(c==0)
          {
              puts(" LIST NOT CREATED, CREATE LIST FIRST ");
             
          }
     else{
     printf("\n Enter the size of the list to be merged \n");
     scanf("%d",&n);
     printf("\n Enter the items of the new list:\n");
     for(i=0;i<n;i++)
     scanf("%d",&a[i]);
     for(i=list_size;i<list_size+n;i++)
     list[i]=a[i-list_size];
     printf("\n List before merging \n");
     for(i=0;i<list_size;i++)
          printf("\t %d",list[i]);
     list_size+=n;
     printf("\n List after merging \n");
     for(i=0;i<list_size;i++)
          printf("\t %d",list[i]);
      }
     return;
}
void sort(int list[],int list_size)
{
     int i,temp,j;
   if(c==0)
          {
              puts(" LIST NOT CREATED, CREATE LIST FIRST ");
             
          }
     else{
     printf("\n List before sorting \n");
     for(i=0;i<list_size;i++)
          printf("\t %d",list[i]);
     for(i=0;i<list_size;i++)
          {
              for(j=i;j<list_size-1;j++)
                   {
                        if(list[i]<list[j])
                             {
                                  temp=list[i];
                                  list[i]=list[j];
                                  list[j]=temp;
                             }
                   }
          }
     printf("\n List after sorting \n");
     for(i=0;i<list_size;i++)
          printf("\t %d",list[i]);
     }
     return;
}
void search(int list[],int list_size)
{
     int item,flag=1,i,count=0,a[10];
   if(c==0)
          {
              puts(" LIST NOT CREATED, CREATE LIST FIRST ");
             
          }
     else{
     printf("\n List items are: \n");
     for(i=0;i<list_size;i++)
          printf("\t %d",list[i]);
     printf("\n Enter the item to be searched:\n");
     scanf("%d",&item);
     for(i=0;i<list_size;i++)
          {
              if(item==list[i])
                   {
                   a[count]=i;
                   count++;
                   flag=1;
                   continue;
                   }
           else
           flag=0;
           }
     if(flag==0 && count==0)
              printf("\n Item not found:\n");
     else
          {
              printf("\n Item %d is at postion",item);
              for(i=0;i<count;i++)
                   printf("\t %d",a[i]+1);
          }
     }
     return;
}
void append(int list[],int list_size)
{
     int item,pos,i;
   if(c==0)
          {
              puts(" LIST NOT CREATED, CREATE LIST FIRST ");
             
          }
     else{
     printf("\n List items are: \n");
     for(i=0;i<list_size;i++)
          printf("\t %d",list[i]);
     printf("\n Enter the item to be appended & position:\n");
     scanf("%d %d",&item,&pos);
     list[pos-1]=item;
     printf("\n List after appending: \n");
     for(i=0;i<list_size;i++)
          printf("\t %d",list[i]);
     }
     return;
}