Re: [问题] 有关链结串行的问题

楼主: Godfrey0216 (Godfrey)   2015-07-27 15:15:38
※ 引述《Godfrey0216 (Godfrey)》之铭言:
: 哈囉大家好唷,我想问一下大家,如果我现在手上有一笔存在矩阵中
: 的资料.我想用利用链结串行让资料印出来,分别是正向跟反向
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <cmath>
using namespace std ;
int isPrime(int p)
{
int i;
for (i=2;i<=sqrt((double)p);i++)
{
if(p%i==0)
return 0 ;
}
return 1 ;
}
struct friendData {
int ans[1024];
};
struct linkedListNode {
struct friendData data;
struct linkedListNode *nextPtr;
};
typedef struct linkedListNode LinkedListNode;
int main()
{
LinkedListNode *startPtr, *newPtr, *currentPtr ;
startPtr = NULL;
int n , c ; int m ; int j ; int r ;
char ch ;
int num[1024] ;
cout << "请输入N值 : " << endl ;
cin >> n ;
newPtr = (LinkedListNode *)malloc(sizeof(LinkedListNode));
for ( int i = 1 ; i <= n ; i++)
{
if( n%i ==0)
{
c++ ;
num[c] = i ;
cout << "第" << c << "个因子 : " << num[c] << endl ;
}
}
cout << "因子总个数为 : " << c << "个" << endl ;
cout << "====================================================" << endl;
for( int i = 1 ; i <=c ; i++ )
{
if(isPrime(num[i]))
cout << num[i] << "为质数" << endl;
else
cout << num[i] << "不为质数" << endl;
}
cout << "====================================================" << endl;
cout << "请选择打印因子方法" << endl;
cout << "1) 正向打印出所有因子 " << endl;
cout << "2) 反向打印出所有因子 " << endl;
cout << "3) 离开 " << endl;
startPtr == NULL;
newPtr->data.ans;
newPtr->nextPtr = NULL;
if (startPtr == NULL) {
startPtr = newPtr;
}
else {
currentPtr = startPtr;
while (currentPtr != NULL) {
if (currentPtr->nextPtr == NULL) {
currentPtr->nextPtr = newPtr;
break;
}
currentPtr = currentPtr->nextPtr;
}
}
while(1){
ch = getchar();
switch(ch){
case '1' :
{
currentPtr = startPtr;
while (currentPtr != NULL)
cout << currentPtr-> data.ans <<endl;
currentPtr = currentPtr->nextPtr;
}
break ;
case '2' :
for (int i=c; i>0; i
作者: stupid0319 (征女友)   2015-07-27 17:58:00
你先试着找看是哪一行印出0x5d5fd0??
作者: Frozenmouse (*冰之鼠*)   2015-07-27 19:19:00
你从头到尾只配了一个node而且也没写资料进去@@另外为何你的node资料要是int阵列?
楼主: Godfrey0216 (Godfrey)   2015-07-27 20:28:00
因为我要他存num[]里面的值,所以开了个阵列给他
作者: Frozenmouse (*冰之鼠*)   2015-07-27 22:12:00
串行本身就是群集的概念,通常你是要存很多个int阵列才可能会这样写…我觉得你应该是想存int吧?XD
楼主: Godfrey0216 (Godfrey)   2015-07-27 22:35:00
不,我在main()里面有用阵列存了我全部的因子而我现在想用串行把这些因子print出来!

Links booklink

Contact Us: admin [ a t ] ucptt.com