herrDeng網內搜尋

自訂搜尋

Ads

2008年10月23日 星期四

ch4 ex7

ch4 ex7

50 則留言:

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;


int data[ ] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}



node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數: "<< node<<"\n";
cout<<"鏈結串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

# include < cstdlib >
# include < iostream >

using namespace std;

int main(void) {
struct List /* 節點結構宣告 */
{
int any;
struct List *next;
} *head, *tail, *tmp;

/* 輸入資料 */
int data[] = {6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {
tmp=new struct List;
tmp-> any = data[i];
tmp-> next = head;
head = tmp;
if (!tail) tail = tmp;
}
/* 計算鏈結串列之節點數目 = 鏈結串列的長度 - 1*/
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp-> next;
}
length = node - 1;
cout<<"鏈結串列之節點數: " << node <<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

# include < cstdlib >
# include < iostream >

using namespace std;

int main(void) {
struct List /* 節點結構宣告 */
{
int any;
struct List *next;
} *head, *tail, *tmp;

/* 輸入資料 */
int data[] = {6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {
tmp=new struct List;
tmp-> any = data[i];
tmp-> next = head;
head = tmp;
if (!tail) tail = tmp;
}
/* 計算鏈結串列之節點數目 = 鏈結串列的長度 - 1*/
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp-> next;
}
length = node - 1;
cout<<"鏈結串列之節點數: " << node <<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

# include < cstdlib >
# include < iostream >

using namespace std;

int main(void) {
struct List /* 節點結構宣告 */
{
int any;
struct List *next;
} *head, *tail, *tmp;

/* 輸入資料 */
int data[] = {6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {
tmp=new struct List;
tmp-> any = data[i];
tmp-> next = head;
head = tmp;
if (!tail) tail = tmp;
}
/* 計算鏈結串列之節點數目 = 鏈結串列的長度 - 1*/
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp-> next;
}
length = node - 1;
cout<<"鏈結串列之節點數: " << node <<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

/*函數:計算節點數*/
int length(){
int tmp_length=0; /*節點數初始為0*/
List current = first; /* 目前的串列指標 */
while ( current != NULL ) { /* 搜尋主迴圈 */
tmp_length++; /* 節點數加一 */
current = current->next; /* 下一個節點 */
}
return tmp_length; /* 回傳節點數 */
}

/*函式: 回傳目的指標的前一個節點指標*/
List previousNode(int d){
List current = first; /*目前的串列指標 */
List pre=NULL; /*前一個串列指標 */
while(current!=NULL){
if(current->data==d){
return pre; /*找到目標指標,回傳前一個指標 */
}
pre=current; /*記錄前一個串列指標 */
current=current->next; /*下一個節點 */
}
return NULL; /*找不到指標,回傳 NULL*/
}

/*函式: 印出前一個節點的內容*/
void printPreviousNode(int d)
{
List findNode;
findNode=searchNode(d); /*用走訪節點函式尋找目標節點 */
if(findNode==NULL)
{
printf("串列不含節點[%d]\n",d); /*若找不到節點則印出結果並回傳 */
return;
}

List pre;
pre=previousNode(d); /*用尋找前一節點的函式來搜尋前一節點*/
if(pre==NULL)
{
printf("您搜尋的節點為第一個節點,故無前一節點\n"); /*若為第一節點,印出結果並回傳*/
return;
}else
{
printf("串列包含節點[%d],前一節點為[%d]\n",d,pre->data); /*印出前一個節點並回傳*/
return;
}
}

匿名 提到...

#include < cstdlib >
#include < iostream >
using namespace std;

int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;

int data[ ] = {1, 9, 2, 3, 6, 5, 4, 7, 2, 8 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"串列節點數: "<< node<<"\n";
cout<<"串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;


int data[ ] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}



node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數: "<< node<<"\n";
cout<<"鏈結串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;

int data[ ] = {7,6,5,4,3,2,1};
int i,j,node,length,len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}

node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數:"<< node<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int every;
struct List *next;
} *ptr, *tail, *temp;

int data[ ] = { 1,2,3,4,5,6,7,8 };
int k,Node,Length;
ptr = tail = NULL;
for (k = 0; k < (sizeof(data)/4); k++)
{
temp=new struct List;
temp->every = data[ k ];
temp->next = ptr;
ptr = temp;
if (!tail) tail = temp;
}
Node = Length = 0;
temp = ptr;
while (temp)
{
Node++;
temp = temp->next;
}
Length = Node - 1;
cout<<"節點數: "<< Node<<"\n";
cout<<"串列長度: "<< Length<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int jp;
struct List *next;
} *en, *tw, *mg;

int data[ ] = { 1,2,3,4,5,6,7,8 };
int x,th,be;
en = tw = NULL;
for (x = 0; x < (sizeof(data)/4); x++)
{
mg=new struct List;
mg->jp = data[ x ];
mg->next = en;
en = mg;
if (!tw) tw = mg;
}
th = be = 0;
mg = en;
while (mg)
{
th++;
mg = mg->next;
}
be = th - 1;
cout<<"節點數: "<< th<<"\n";
cout<<"串列長度: "<< be<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;

int main( void) {
struct List
{
int ab;
struct List *next;
} *cd, *ef, *gh;

int data[ ] = { 1,2,3,4,5,6,7,8 };
int y,ij,kl;
cd = ef = NULL;
for (y = 0; y < (sizeof(data)/4); y++)
{
gh=new struct List;
gh->ab = data[ y ];
gh->next = cd;
cd = gh;
if (!ef) ef = gh;
}
ij = kl = 0;
gh = cd;
while (gh)
{
ij++;
gh = gh->next;
}
kl = ij - 1;
cout<<"節點數: "<< ij<<"\n";
cout<<"串列長度: "<< kl<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int every;
struct List *next;
} *ptr, *tail, *temp;

int data[ ] = { 1,2,3,4,5,6,7,8 };
int f,Node,Length;
ptr = tail = NULL;
for (f = 0; f < (sizeof(data)/4); f++)
{
temp=new struct List;
temp->every = data[ f ];
temp->next = ptr;
ptr = temp;
if (!tail) tail = temp;
}
Node = Length = 0;
temp = ptr;
while (temp)
{
Node++;
temp = temp->next;
}
Length = Node - 1;
cout<<"鏈結節點數: "<< Node<<"\n";
cout<<"鏈結串列長度: "<< Length<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib>
#include < iostream>

using namespace std;

int main(void)
{

struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;

int data[ ] = { 8,2,7,4,5,6,1,3 };
int i, j, node, length, len;
head = tail = NULL;
for (i = 0; i < (sizeof(data)/4); i++)
{
tmp=new struct List;
tmp->any = data[i];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}
node = length = 0;
tmp = head;
while (tmp)
{
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"節點數: "<< node<<"\n";
cout<<"串列長度: "<< length<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;

int main(void)
{

struct List
{
int jp;
struct List *next;
} *ptr, *tail, *tmp;

int data[ ] = {7,6,5,4,3,2,1};
int i,th,be;
ptr = tail = NULL;
for (i = 0; i < (sizeof(data)/4); i++)
{
tmp=new struct List;
tmp->jp = data[ i ];
tmp->next = ptr;
ptr = tmp;
if (!tail) tail = tmp;
}
th = be = 0;
tmp = ptr;
while (tmp)
{
th++;
tmp = tmp->next;
}
be = th - 1;
cout<<"節點數: "<< th<<"\n";
cout<<"串列長度: "<< be<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

7.length()函數:

struct newnode
{
int data;
struct newnode *next;
};
typedef struct newnode LNode;
typedef LNode *List;
List first = NULL;
void creatlist(int len, int *array)
{
int i;
List newnode;
for( i=0; i < len; i++)
{
newnode=(List)malloc(sizeof(LNode));
newnode ->d ata = array[i];
newnode -> next = first;
first = newnode;
}
}
int main()
{
int length;
List current = first;
while(current != NULL)
{
current = current -> next;
}
length = current - first;

7.previousNode():

struct newnode
{
int data;
struct Node *next;
struct Node *previous;
};
typedef struct newnode DNode;
typedef DNode *DList;
DList first = NULL;
DList now = NULL;
void creatDList(int len, int *array)
{
int i;
DList newnode, before;
first=(DList)malloc(sizeof(DNode));
first -> data = array[0];
first -> previous = NULL;
before = first;
now = first;
for( i=1; i < len; i++)
{
newnode=(DList)malloc(sizeof(DNode));
newnode -> data = array[i];
newnode -> next = NULL;
newnode -> previous = before;
before -> next = newnode;
before = newnode;
}
}
void previousnode()
{
if(now -> previous != NULL)
now = now -> previous;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;


int data[ ] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}



node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數: "<< node<<"\n";
cout<<"鏈結串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;


int data[ ] = {4,5,6,1,9 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}



node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數: "<< node<<"\n";
cout<<"鏈結串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

previousNode():

int main() {
int temp = 1;
int data[3]={1,2,3};
createDList(3、data);
while ( temp != 1 ) {
printDList();
switch ( temp ) {
previousNode();
break;
}
}
system("PAUSE");
return 0;
}
老師 我投降了

匿名 提到...

length():
#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int every;
struct List *next;
} *ptr、*tail、*temp;

int data[ ] = {1,2,3,4,5,6};
int z,Node,Length;
ptr = tail = NULL;
for (z = 0; z < (sizeof(data)/4); k++)
{
temp=new struct List;
temp->every = data[ z ];
temp->next = ptr;
ptr = temp;
if (!tail) tail = temp;
}
Node = Length = 0;
temp = ptr;
while (temp)
{
Node++;
temp = temp->next;
}
Length = Node - 1;
cout<<"節點數: "<< Node<<"\n";
cout<<"串列的長度: "<< Length<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

我真的認輸了

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;

int data[ ] = {7,6,5,4,3,2,1};
int i,j,node,length,len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}

node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數:"<< node<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

# include < cstdlib >
# include < iostream >

using namespace std;

int main(void) {
struct List /* 節點結構宣告 */
{
int any;
struct List *next;
} *head, *tail, *tmp;

/* 輸入資料 */
int data[] = {6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {
tmp=new struct List;
tmp-> any = data[i];
tmp-> next = head;
head = tmp;
if (!tail) tail = tmp;
}

/* 計算鏈結串列之節點數目 = 鏈結串列的長度 - 1*/
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp-> next;
}

length = node - 1;
cout<<"鏈結串列之節點數: " << node <<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

# include < cstdlib >
# include < iostream >

using namespace std;

int main(void) {
struct List /* 節點結構宣告 */
{
int any;
struct List *next;
} *head, *tail, *tmp;

/* 輸入資料 */
int data[] = {6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {
tmp=new struct List;
tmp-> any = data[i];
tmp-> next = head;
head = tmp;
if (!tail) tail = tmp;
}

/* 計算鏈結串列之節點數目 = 鏈結串列的長度 - 1*/
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp-> next;
}

length = node - 1;
cout<<"鏈結串列之節點數: " << node <<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;


int data[ ] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}



node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數: "<< node<<"\n";
cout<<"鏈結串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

# include < cstdlib >
# include < iostream >

using namespace std;

int main(void) {
struct List /* 節點結構宣告 */
{
int any;
struct List *next;
} *head, *tail, *tmp;

/* 輸入資料 */
int data[] = {6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {
tmp=new struct List;
tmp-> any = data[i];
tmp-> next = head;
head = tmp;
if (!tail) tail = tmp;
}
/* 計算鏈結串列之節點數目=鏈結串列的長度 - 1*/
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp-> next;
}
length = node - 1;
cout<<"鏈結串列之節點數: " << node <<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int jp;
struct List *next;
} *en, *tw, *mg;

int data[ ] = { 1,2,3,4,5,6,7,8 };
int x,th,be;
en = tw = NULL;
for (x = 0; x < (sizeof(data)/4); x++)
{
mg=new struct List;
mg->jp = data[ x ];
mg->next = en;
en = mg;
if (!tw) tw = mg;
}
th = be = 0;
mg = en;
while (mg)
{
th++;
mg = mg->next;
}
be = th - 1;
cout<<"節點數: "<< th<<"\n";
cout<<"串列長度: "<< be<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;
int data[ ] = {13, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {
tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}

length = node - 1;
cout<<"鏈結串列節點數: "<< node<<"\n";
cout<<"鏈結串列長度: "<< length<<"\n";

匿名 提到...

int main(void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;

int data[] = {6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {
tmp=new struct List;
tmp-> any = data[i];
tmp-> next = head;
head = tmp;
if (!tail) tail = tmp;
}

node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp-> next;
}
length = node - 1;
cout<<"鏈結串列之節點數: " << node <<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;

int data[ ] = {7,6,5,4,3,2,1};
int i,j,node,length,len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}

node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數:"<< node<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int qq;
struct List *next;
} *rr, *bb, *cc;

int data[ ] = { 1,2,3,4,5 };
int a,b,c;
rr = bb = NULL;
for (a = 0; a < (sizeof(data)/4); a++)
{
cc=new struct List;
cc->qq = data[ a ];
cc->next = rr;
rr = cc;
if (!bb) bb = cc;
}
b = c = 0;
cc = rr;
while (cc)
{
b++;
cc = cc->next;
}
c = b - 1;
cout<<"節點數: "<< b<<"\n";
cout<<"串列長度: "<< c<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >
using namespace std;

int main( void) {
struct List
{
int any;
struct List *next;
} *head、*tail、*tmp;

int data[ ] = {9、6、3、3、0、6、2};
int x、y、node、length、len;

head = tail = NULL;
for (x = 0; x < (sizeof(data)/sizeof(int)); x++) {

tmp=new struct List;
tmp->any = data[ x ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"串列節的點數: "<< node<<"\n";
cout<<"串列的長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void ) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;


int data[ ] = {8,7,6,5,4,3,2,1 };
int a, b, node, length, len;

head = tail = NULL;
for (a = 0; a < (sizeof(data)/sizeof(int)); a++) {

tmp=new struct List;
tmp->any = data[ a ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}



node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數: "<< node<<"\n";
cout<<"鏈結串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >
using namespace std;

int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;

int data[ ] = {7, 6, 5, 4, 3, 2, 1};
int i, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"串列節點數: "<< node<<"\n";
cout<<"串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;

int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;

int data[ ] = {8, 7, 6, 5, 4, 3, 2, 1};
int i, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"串列的節點數是? "<< node<<"\n"<<"\n";
cout<<"串列的長度是? "<< length<<"\n"<<"\n"<<"\n";



system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void ) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;


int data[ ] = {9,8,7,6,5,4,3,2,1 };
int a, b, node, length, len;

head = tail = NULL;
for (a = 0; a < (sizeof(data)/sizeof(int)); a++) {

tmp=new struct List;
tmp->any = data[ a ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}



node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數::"<< node<<"\n";
cout<<"鏈結串列長度::"<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;

int main( void) {
struct List
{
int pi;
struct List *next;
} *yp, *tm, *tmp;

int data[ ] = {2, 1, 6, 7, 3, 4, 9, 5, 8};
int i, j, node, length, len;

yp = tm = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->pi = data[ i ];
tmp->next = yp;
yp = tmp;
if (!tm) tm = tmp;
}

node = length = 0;
tmp = yp;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"串列節點數: "<< node<<"\n";
cout<<"串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;

int main( void) {
struct List
{
int pi;
struct List *next;
} *yp, *tm, *tmp;

int data[ ] = {8, 9, 1, 2, 3, 4, 7, 5, 6};
int i, j, node, length, len;

yp = tm = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->pi = data[ i ];
tmp->next = yp;
yp = tmp;
if (!tm) tm = tmp;
}

node = length = 0;
tmp = yp;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"串列節點數: "<< node<<"\n";
cout<<"串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;

int main( void) {
struct List
{
int ab;
struct List *next;
} *cd, *ef, *gh;

int data[ ] = { 1,2,3,4,5,6,7,8 };
int y,ij,kl;
cd = ef = NULL;
for (y = 0; y < (sizeof(data)/4); y++)
{
gh=new struct List;
gh->ab = data[ y ];
gh->next = cd;
cd = gh;
if (!ef) ef = gh;
}
ij = kl = 0;
gh = cd;
while (gh)
{
ij++;
gh = gh->next;
}
kl = ij - 1;
cout<<"節點數: "<< ij<<"\n";
cout<<"串列長度: "<< kl<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;

int data[ ] = {7,6,5,4,3,2,1};
int i,j,node,length,len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}

node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數:"<< node<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >
using namespace std;

int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;

int data[ ] = {9, 8, 7, 6, 5, 4, 3, 2,1 };
int x, y, node, length, len;

head = tail = NULL;
for (x = 0; x < (sizeof(data)/sizeof(int)); x++) {

tmp=new struct List;
tmp->any = data[ x ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"串列節點數: "<< node<<"\n";
cout<<"串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;

int main( void) {
struct List
{
int pi;
struct List *next;
} *yp, *tm, *tmp;

int data[ ] = {8, 9, 1, 2, 3, 4, 7, 5, 6};
int i, j, node, length, len;

yp = tm = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->pi = data[ i ];
tmp->next = yp;
yp = tmp;
if (!tm) tm = tmp;
}

node = length = 0;
tmp = yp;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"串列節點數: "<< node<<"\n";
cout<<"串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;

int main( void) {
struct List
{
int pi;
struct List *next;
} *yp, *tm, *tmp;

int data[ ] = {8, 9, 1, 2, 3, 4, 7, 5, 6};
int i, j, node, length, len;

yp = tm = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->pi = data[ i ];
tmp->next = yp;
yp = tmp;
if (!tm) tm = tmp;
}

node = length = 0;
tmp = yp;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"串列節點數: "<< node<<"\n";
cout<<"串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

# include < cstdlib >
# include < iostream >

using namespace std;

int main(void) {
struct List /* 節點結構宣告 */
{
int any;
struct List *next;
} *head、*tail、*tmp;

/* 輸入資料 */
int data[] = {6、5、4、3、2、1 };
int i、j、node、length、len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {
tmp=new struct List;
tmp-> any = data[i];
tmp-> next = head;
head = tmp;
if (!tail) tail = tmp;
}
/* 計算鏈結串列之節點數目 = 鏈結串列的長度 - 1*/
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp-> next;
}
length = node - 1;
cout<<"鏈結串列之節點數: " << node <<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

b9633068 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int every;
struct List *next;
} *ptr, *tail, *temp;

int data[ ] = { 1,2,3,4,5,6,7,8 };
int f,Node,Length;
ptr = tail = NULL;
for (f = 0; f < (sizeof(data)/4); f++)
{
temp=new struct List;
temp->every = data[ f ];
temp->next = ptr;
ptr = temp;
if (!tail) tail = temp;
}
Node = Length = 0;
temp = ptr;
while (temp)
{
Node++;
temp = temp->next;
}
Length = Node - 1;
cout<<"鏈結節點數: "<< Node<<"\n";
cout<<"鏈結串列長度: "<< Length<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void ) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;


int data[ ] = {9,8,7,6,5,4,3,2,1 };
int a, b, node, length, len;

head = tail = NULL;
for (a = 0; a < (sizeof(data)/sizeof(int)); a++) {

tmp=new struct List;
tmp->any = data[ a ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}



node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數::"<< node<<"\n";
cout<<"鏈結串列長度::"<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

# include < cstdlib >
# include < iostream >

using namespace std;

int main(void) {
struct List /* 節點結構宣告 */
{
int any;
struct List *next;
} *head, *tail, *tmp;

/* 輸入資料 */
int data[] = {6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {
tmp=new struct List;
tmp-> any = data[i];
tmp-> next = head;
head = tmp;
if (!tail) tail = tmp;
}
/* 計算鏈結串列之節點數目 = 鏈結串列的長度 - 1*/
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp-> next;
}
length = node - 1;
cout<<"鏈結串列之節點數: " << node <<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;

int data[ ] = {7,6,5,4,3,2,1};
int i,j,node,length,len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {

tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}

node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數:"<< node<<"\n";

system("PAUSE");
return EXIT_SUCCESS;

匿名 提到...

struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;
int data[ ] = {13, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {
tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp->next;
}

length = node - 1;
cout<<"鏈結串列節點數: "<< node<<"\n";
cout<<"鏈結串列長度: "<< length<<"\n";

匿名 提到...

# include < cstdlib >
# include < iostream >

using namespace std;

int main(void) {
struct List /* 節點結構宣告 */
{
int any;
struct List *next;
} *head, *tail, *tmp;

/* 輸入資料 */
int data[] = {6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++) {
tmp=new struct List;
tmp-> any = data[i];
tmp-> next = head;
head = tmp;
if (!tail) tail = tmp;
}
/* 計算鏈結串列之節點數目 = 鏈結串列的長度 - 1*/
node = length = 0;
tmp = head;
while (tmp) {
node++;
tmp = tmp-> next;
}
length = node - 1;
cout<<"鏈結串列之節點數: " << node <<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int any;
struct List *next;
} *head, *tail, *tmp;


int data[ ] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
int i, j, node, length, len;

head = tail = NULL;
for (i = 0; i < (sizeof(data)/sizeof(int)); i++)
{
tmp=new struct List;
tmp->any = data[ i ];
tmp->next = head;
head = tmp;
if (!tail) tail = tmp;
}



node = length = 0;
tmp = head;
while (tmp)
{
node++;
tmp = tmp->next;
}
length = node - 1;
cout<<"鏈結串列節點數: "<< node<<"\n";
cout<<"鏈結串列長度: "<< length<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

匿名 提到...

#include < cstdlib >
#include < iostream >

using namespace std;


int main( void) {
struct List
{
int qq;
struct List *next;
} *rr, *bb, *cc;

int data[ ] = { 1,2,3,4,5 };
int a,b,c;
rr = bb = NULL;
for (a = 0; a < (sizeof(data)/4); a++)
{
cc=new struct List;
cc->qq = data[ a ];
cc->next = rr;
rr = cc;
if (!bb) bb = cc;
}
b = c = 0;
cc = rr;
while (cc)
{
b++;
cc = cc->next;
}
c = b - 1;
cout<<"節點數: "<< b<<"\n";
cout<<"串列長度: "<< c<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}

Related Posts Plugin for WordPress, Blogger...

熱門文章