本文介绍了如何从C链表中用户输入的结构中减去整数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码在这里我试图用用户输入值(x1)减去struct node中的itemnum ....但它无法正常工作。







Below is my code here i am trying to subtract itemnum in struct node with user input value (x1) ....but it is not working properly .



struct node                                                   // main structure
{
        int itemcode;
        int itemnum;                             //itemnum
        char name[30];
        struct node *next;
}
struct node *create,*end,*start,*temp,*prev,*temp1,*start1,*end1;
int x,y,x1,num,total;


void orderitem( int x,int x1)         // I am passing item code and itemnum 
{


    if(isempty())                        // function to check head pointer is !null
    {

        printf("Empty, can't order now");
    }
    else
    {

        temp=start;
        while(temp->next!=NULL && temp->itemcode!= x)
        {
            prev=temp;
            temp = temp-> next;
        }

        if(temp->next==NULL&&temp->itemcode!=x)  // searching with x i.e item code

        {
            printf("Element %d is not present in the list\n",x);
            return;
        }

        else if(start->itemcode==x)              //if item code is at first 
        {
            start1->itemnum=x1;

            start->itemnum-=start1->itemnum;

            if(start->itemnum<=0)         //deletes start if itemnumber less than 0
            {         
                start=start->next;
            }
        }
        else if(end->itemcode==x)              //checks the item code with end  pos
        {                                             

            end1->itemnum=x1;
            end->itemnum-=end1->itemnum;
        }
        if(end->itemnum<=0)                       //deletes end 
        {   end=prev;
            end->next=NULL;

        }


        else
        {
                temp1->itemnum=x1;                 //storing user's item number in  
                                                      temp1

                temp->itemnum-=temp1->itemnum;       

                if(temp->itemnum<=0)
                    prev->next=temp->next;

           
        }

    }
}





我尝试了什么:



我尝试过结构变量来保存用户输入并减去它在结构中的项目编号....但它不起作用......我是数据结构的新手,......代码可能不那么好......但如果有人可以告诉我减去过程的程序,我将非常感激。具有用户输入值的项目编号。谢谢



What I have tried:

I have tried structure variable to hold the user input and minus it with item number in struct ....but it didn't work......I am new to data structures,....the code may not be that good....but it would be hugely appreciated if someone can tell me the procedure to minus the item number with user input value. thanks

推荐答案



这篇关于如何从C链表中用户输入的结构中减去整数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 03:19