首页 \ 问答 \ 在排序链表时存储节点的变量(Variables to store node while sorting linked list)

在排序链表时存储节点的变量(Variables to store node while sorting linked list)

我是一个遥远的学习学生,这次我会问社区'去哪里'。 该程序使用链表生成操作。 我理解有关节点的三个指针和两个要比较的候选者的想法。 与此同时,我没有意识到节点中临时存储信息的想法。 我应该声明节点的结构大小还是使用单独声明的变量?

提前谢谢了!

/* Define libraries to be included */
#include <stdio.h>/*standard input & out library*/
#include <malloc.h>/*allocate memory block*/ 
#include <string.h>/*defines memory functions to manipulate strings 
                   and arrays*/
#include <ctype.h>/*classifies and transform characters*/

#include <iomanip>

using namespace std;

/*----------------------------------------------------------------------*/
/* define structure
there is no difference btw struct & class*/
typedef struct client {
    int number; /*unique account number*/
    int balance;/*balance*/
    char lastName[20]; /*contains family name*/
    char firstName [20];/*contains name*/
    char phone[20]; /*contains phone number 10 digits*/
    char email[20];
    struct client *prev;/* pointer is used to navigate through list
                         of structures*/
    struct client *next; 
    /*next is used to navigate through structures.*/

} Client;
Client *firstc,*currentc,*newc;  /*pointers*/
/* 'firstc' is used to point to first record in list
   'currentc' points to current record in list
   'newc' contains address of new structure/node
*/

/*-------------------------------------------*/
voidSort()
{
/*temporary pointer to head of list*/
struct client *temphead;

/*variables */
    /* stumbling point: I suppose it's not correct*/
int tempnumber; /*unique account number*/
int tempbalance;/*balance*/
char templastName[20]; /*contains family name*/
char tempfirstName [20];/*contains name*/
char tempphone[20]; /*contains phone number 10 digits*/
char tempemail[20];
/*variable to count iterations */
int counter;

if (firstc!==NULL)
/*switch to head of list*/
struct client *temphead = firstc;

while(temphead)
{
    /* */
    temphead = temphead->next;
    counter++;

}
temphead = firstc;

for (int j = 0; j<coiunter; j++)
    while(temphead->next)
    {   
        if(temphead->balance > temphead->next->balance)
        {   
            tempbalance = temphead->balance; //
            temphead->balance = temphead->next->balance; //
            temphead->next->balance = tempbalance;//

            tempnumber = temphead->number;
            temphead->number = temphead->next->number;
            temphead->next->number = tempnumber;

            templastName = temphead->lastName
            //.......................
        }
        else
            temphead = temphead->next;
    }   
    temphead = firstc;
}

I'm a distant learning student and this time I would ask community 'where to go'. This program produce operations with linked list. I understand the idea about three pointers to nodes and two candidates to compare. At the same time I didn't catch the idea about temporary storage of information in the node. Should I declare structure size of node or use individually declared variables?

Many thanks in advance!

/* Define libraries to be included */
#include <stdio.h>/*standard input & out library*/
#include <malloc.h>/*allocate memory block*/ 
#include <string.h>/*defines memory functions to manipulate strings 
                   and arrays*/
#include <ctype.h>/*classifies and transform characters*/

#include <iomanip>

using namespace std;

/*----------------------------------------------------------------------*/
/* define structure
there is no difference btw struct & class*/
typedef struct client {
    int number; /*unique account number*/
    int balance;/*balance*/
    char lastName[20]; /*contains family name*/
    char firstName [20];/*contains name*/
    char phone[20]; /*contains phone number 10 digits*/
    char email[20];
    struct client *prev;/* pointer is used to navigate through list
                         of structures*/
    struct client *next; 
    /*next is used to navigate through structures.*/

} Client;
Client *firstc,*currentc,*newc;  /*pointers*/
/* 'firstc' is used to point to first record in list
   'currentc' points to current record in list
   'newc' contains address of new structure/node
*/

/*-------------------------------------------*/
voidSort()
{
/*temporary pointer to head of list*/
struct client *temphead;

/*variables */
    /* stumbling point: I suppose it's not correct*/
int tempnumber; /*unique account number*/
int tempbalance;/*balance*/
char templastName[20]; /*contains family name*/
char tempfirstName [20];/*contains name*/
char tempphone[20]; /*contains phone number 10 digits*/
char tempemail[20];
/*variable to count iterations */
int counter;

if (firstc!==NULL)
/*switch to head of list*/
struct client *temphead = firstc;

while(temphead)
{
    /* */
    temphead = temphead->next;
    counter++;

}
temphead = firstc;

for (int j = 0; j<coiunter; j++)
    while(temphead->next)
    {   
        if(temphead->balance > temphead->next->balance)
        {   
            tempbalance = temphead->balance; //
            temphead->balance = temphead->next->balance; //
            temphead->next->balance = tempbalance;//

            tempnumber = temphead->number;
            temphead->number = temphead->next->number;
            temphead->next->number = tempnumber;

            templastName = temphead->lastName
            //.......................
        }
        else
            temphead = temphead->next;
    }   
    temphead = firstc;
}

原文:https://stackoverflow.com/questions/16622228
更新时间:2023-08-28 13:08

最满意答案

您不能修改常量值(使用const修饰符标记的变量)。

你有两个选择:

1)从场中删除const

2)使用格式化在常量字符串中的占位符中插入值:

const string url = "http://smsmobile24.com/components/com_spc/smsapi.php?username=C***er&password=fath****am&sender=Cmanager&recipient={0}&message={1}";

var to = smsRecipientBox.Text;
var msg = smsMsgBox.Text;

string result = string.Format(url, to, msg);

You can't modify a constant value (variable that is marked with const modifier).

You have two options here:

1) you remove the const from the field

2) use formatting to insert values in placeholders in the constant string:

const string url = "http://smsmobile24.com/components/com_spc/smsapi.php?username=C***er&password=fath****am&sender=Cmanager&recipient={0}&message={1}";

var to = smsRecipientBox.Text;
var msg = smsMsgBox.Text;

string result = string.Format(url, to, msg);

相关问答

更多
  • **免责声明:Twilio福音传教士** 奇拉格: 所以听起来你有两个要求: 使用Twilio将出站文本消息发送给不同的收件人 捕获用户对该消息的回复 对于第一个要求,您可以先访问Twilio.com并注册新帐户。 它是免费的,我们会为您提供一个Twilio电话号码,您可以使用它来开始构建您的应用程序。 一旦拥有Twilio电话号码,就可以使用REST API开始发送来自该Twilio电话号码的出站短信。 我们有一个快速入门,向您展示如何执行此操作: http://www.twilio.com/docs/q ...
  • 那么我找到了一些解决方案,将用户重定向到各自的市场。 解决方案1 使用第三方工具,您可以通过短信发送单个链接,当用户点击该链接时,他们将重定向到市场。 下面是一些链接,可帮助您获取移动应用程序的单一链接。 一个链接 分支指标 还有很多 解决方案2 制作一个网页,您必须检查用户的设备和条件以将用户重定向到应用商店。 通过短信发送网页链接。 希望这会对一些人有所帮助。 Well I found some solution for redirecting users to there respective mar ...
  • 如果您正在寻找短信服务提供商? 你可以试试Clickatell 如果您正在考虑创建一个短信api,请查看Twitter API If you looking for a sms service provider? You could try Clickatell If you looking at creating a sms api, look at the Twitter API
  • 您不能修改常量值(使用const修饰符标记的变量)。 你有两个选择: 1)从场中删除const 2)使用格式化在常量字符串中的占位符中插入值: const string url = "http://smsmobile24.com/components/com_spc/smsapi.php?username=C***er&password=fath****am&sender=Cmanager&recipient={0}&message={1}"; var to = smsRecipientBox.Text; ...
  • 如果您在没有代理的情况下从网络外部连接时遇到问题,则可以在服务器启动期间使用以下jvm参数来提供代理配置。 例如: sh wso2server.sh -Dhttp.proxyHost=10.0.0.100 -Dhttp.proxyPort=8000 -Dhttp.nonProxyHosts="localhost|127.0.0.1|10.*.*.*" If you are having issues with connecting outside from your network without a p ...
  • 你忘了把例程放在括号中的“else”的情况下。 它应该是这样的: else { $this->strMessage=urlencode( $this->strMessage ); try { //Smpp http Url to send sms. $live_url = "http://".$this->host . ":" . $this->port."/bulksms/bulksms?username = ".$this->strUserNa ...
  • 请看http://fortumo.com/api 似乎有你需要的功能:) Look at http://fortumo.com/api Seems to has the features you need:)
  • 尝试添加以下依赖项: compile "com.google.android.gms:play-services-auth-api-phone:$playServicesVersion" Try adding the following dependency: implementation "com.google.android.gms:play-services-auth-api-phone:$playServicesVersion" replace $playServicesVersion with ...
  • 它已被弃用,因为它是Legacy REST API的一部分,虽然它仍然可用,但正逐步淘汰支持Graph API(在某种程度上,FQL)。 我怀疑该权限仍然存在,以便开发人员有时间更新仍使用REST API的应用程序。 It has been deprecated, insofar as it is part of the Legacy REST API, which while still functional, is being phased out in favour of the Graph API ...
  • 您必须打开到端口444的TCP套接字。如何做到这取决于您使用的语言,例如:PHP中的fsockopen ,Python中的套接字模块或.net中的system.net.sockets.socket 。 然后继续从响应中发送行,每行以换行符结束( \n )。 如果您愿意,您可以使用协议,而无需使用Windows中的Telnet或Linux / Unix中的netcat对客户端进行编程。 只需使用server / port作为参数运行程序,具体取决于您使用的冒号(:)分隔,如原始帖子或空格。 You'll ha ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)