私は遠隔学習の学生で、今回はコミュニティに「どこへ行くべきか」を尋ねます。このプログラムは、リンクされたリストを使用して操作を生成します。ノードへの 3 つのポインターと比較する 2 つの候補についてのアイデアを理解しています。同時に、ノードに情報を一時的に保存するというアイデアも思いつきませんでした。ノードの構造サイズを宣言するか、個別に宣言された変数を使用する必要がありますか?
よろしくお願いします!
/* 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;
}