Jump to content

Conclusion in the list

- - - - -

  • Please log in to reply
3 replies to this topic

#1
zhenya

zhenya

    Newbie

  • Members
  • PipPip
  • 13 posts
Problem: the information entered in the enclosed list is not deduced.
What at me it is not correct?
 
struct list{
        char aa[22];
        list *next;
        struct list2 *p2,*cur2,*prev2,*top2;
}*p,*top,*prev,*cur;
struct list2{
        char xx[22];
        list2 *next;
};
 
void push()
{
        top=0;
        int n,i,k=0;
        printf("\n size:\n");
        scanf("%i",&n);
        printf("\n Input:\n");
        for(;n;n--)
        {
                p=new list;
                scanf("%s",&p->aa);
                p->next=NULL;
                while(cur && p->aa >cur->aa)
                {
                        prev=cur;
                        cur=cur->next;
                }
                if(prev==NULL)
                {
                        p->next=top;
                        top=p;
                }
                else
                {
                        p->next=cur;
                        prev->next=p;
                }
        }
        p=top;
        while(p)
        {
                p->p2=p->top2;
                printf("%s",p->aa);
                printf("\n size (inside):\n");
                scanf("%i",&i);
                printf("\n input: ( push into inside\n");
                for(;i;i--)
                {
                        p->p2=new list2;
                        scanf("%s",&p->p2->xx);
                        if(!k){
                                p->top2=NULL;
                                k++;
                        }
                        p->p2->next=NULL;
                        while(p->cur2 && p->p2->xx > p->cur2->xx)
                        {
                                p->prev2=p->cur2;
                                p->cur2=p->cur2->next;
                        }
                        if(p->prev2==NULL)
                        {
                                p->p2->next=p->top2;
                                p->top2=p->p2;
                        }
                        else
                        {
                                p->p2->next=p->cur2;
                                p->prev2->next=p->p2;
                        }
                }
                k=0;
                p=p->next;
        }
}
void show()
{
        p=top;
        if(p==NULL) printf("\n list is empty\n");
        while(p)
        {
                printf(" %s",p->aa);
                p->p2=p->top2;
                while(p->p2)
                {
                        printf("%s",p->p2->xx);
                        p->p2=p->p2->next;
                }
                p=p->next;
        }
}
void main()
{
        push();
        show();
        system("PAUSE");
}


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Can you provide sample input and output, along with what you want it to be?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
zhenya

zhenya

    Newbie

  • Members
  • PipPip
  • 13 posts
(Sample input and output)
I enter:
Andri
7
8
Henry
9
2
as shown:
Andri
Henry


#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
That can't be your input/output. The first input needs to be an integer, which means "Andri" will get skipped over.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users