資料結構 單連結串列 倒序,資料結構 順序表和連結串列問題

2025-01-27 08:35:25 字數 1378 閱讀 2390

1樓:網友

其實就是單連結串列的逆置啊。

#include ""

#include ""

#define null 0

struct node /*定義結構體*/int data;

struct node *next;

struct node *head;

struct node *p;

struct node *q;

void creat() 建立單連結串列*/

int ch;

head=(struct node *)malloc(sizeof(struct node));

head->next=null;

p=head;

printf("請輸入資料: "

scanf("%d",&ch);

while(ch!=-1)

q=(struct node *)malloc(sizeof(struct node));

q->data=ch;

q->next=null;

p->next=q;

p=q;printf("請輸入資料: "

scanf("%d",&ch);

void outline() 輸出單連結串列*/p=head->next;

while(p!=null)

printf("%d ",p->data);

p=p->next;

printf("");

逆置單連結串列*/

void nizhi()

p=head->next;

head->next=null;

while(p!=null)

q=p->next;

p->next=head->next;

head->next=p;

p=q;void main()

creat();

nizhi();

outline();

資料結構 順序表和連結串列問題

2樓:網友

順序表 :資料間的關係是以實際記憶體位置關係存放//實際就是陣列。。。陣列找元素和修改很快~~直接下標 例:char s[100] s[80]='a';

但是要往陣列插入或者刪除元素,要移動的元素太多。

而連結串列 資料間的關係是以指標作為聯絡。

每次查詢元素都是從頭開始。一直到末尾。所以查詢很麻煩。

但是連結串列在新增和刪除直接就是指標的值的改變。元素存放的位置並不會移動。

總結:乙個乙個找到位置 那是查詢功能。。。

連結串列查詢元素需要從頭到尾,所以很慢,但是查詢到後替換很快。(替換快)而陣列則是查詢快(下標),但是替換慢(因為插入或者刪除要挪動大量的元素)。

資料結構(C語言版),單連結串列問題

d正確q next p next的意思 讓q中指向下一個節點的指標指向p的下一個節點 此題中p還沒有插入佇列,所以p的下一個節點不確定,所以這個語句錯誤。p next q next意思 讓p中指向下一個節點的指標指向q的下一個節點 此題中,這條語句執行完後再讓q 的下一個節點指向p就達到目的可能說的...

資料結構考試題,資料結構試卷

void inorder bitree root else 這就是中序遍歷的演算法 include include define maxsize 64 typedef char datatype typedef struct node bitree bitree creatree r q r s i...

資料結構c語言描述,資料結構(C語言描述)

include include include define datatype int define maxsize 1000 typedef struct nodebitreenode datatype bt maxsize bitreenode buildbtree datatype bt,in...