I have got a small problem with this program. It takes a user's input of numbers
and sorts them by merge sort in increasing order using linked lists.
Unfortunately, a segmentation fault appears immediately after I input the numbers. Probably something to do with the merge sort function.
Help!
[code]

include
include

using namespace std;
int psize,qsize,k,i;
struct node
{
int info;
node next;
}
p,q,front,front1,rear1,rear,newptr,ptr,np,np1;
node
create_new_node(int);
void insert (node );
void insert1 (node
);
void display(node );
void MergeSort(node
,int);
void copy(node ,node );

int main()
{
int length=0;
front=rear=NULL;
int inf;
char ch='y';
inf=INT_MIN;
newptr=create_new_node(inf); //assigning least integer value to first node
if(newptr==NULL)
{
cout<<"\nCannot create new node..";
return 0;
}
insert(newptr); //calling fuction to insert new node to the linked list
while(ch=='y'||ch=='Y')
{
cout<<"\nEnter information for the new node..";
cin>>inf;
newptr=create_new_node(inf);
if(newptr==NULL) //checking if new node creation is successful
{
cout<<"\nCannot create new node..";
return 0;
}
insert(newptr);
length++;
cout<<"\nNow the list is:\n";
display(front);
cout<<"\nPress Y to enter more nodes, N to exit..";
cin>>ch;
}
MergeSort(front,length);
}

void MergeSort(node *np,int len)
{
p = np ;
q = np ;

    int k = 1;
    for ( i=0;i<k;i++)
        {
            q = q->next;
        }
    qsize = 0;
    psize=0 ;
    int counter = 0 ;
    while(k<=len/2)
        {
            while (counter<len)
                {
                    while((psize<k)&&(qsize<k))
                        {
                            if((q==NULL)&&(p==NULL))
                            break;

                            if((q->info)<(p->info))
                                {
                                    newptr = create_new_node(q->info);
                                    insert1(newptr);
                                    q = q->next;
                                    qsize++;
                                    counter++;
                                }
                            else
                                {
                                    newptr = create_new_node(p->info);
                                    insert1(newptr);
                                    p = p->next;
                                    psize++;
                                    counter++;
                                }
                        }
                    p = q;
                    for ( i=0;i<k;i++)
                        {
                            q = q->next;
                        } ...

setw(15) what does this command do ?? and also where have u included the command to input characters from the file ???

zandiago commented: are you blind????????? +0

hey just a small question .. jus started out programmin in c ++ ..what does this command do in the above program??
system("pause");
system("cls");

thanx.,..
[email]tonykjose@gmail.com[/email]

hey m a college student .. so probably not as experienced as any of u guys ..but wud luv ta learn!!