日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

数组重复次数最多的元素递归_在不使用递归的情况下计算链接列表中元素的出现次数...

發(fā)布時間:2025/3/11 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数组重复次数最多的元素递归_在不使用递归的情况下计算链接列表中元素的出现次数... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

數(shù)組重復次數(shù)最多的元素遞歸

Solution:

解:

Input:

輸入:

A singly linked list whose address of the first node is stored in a pointer, say head and key is the data of which we have to count the number of occurrences.

一個單鏈表 ,其第一個節(jié)點的地址存儲在一個指針中,例如head和key是我們必須計算其出現(xiàn)次數(shù)的數(shù)據(jù)。

Output:

輸出:

The number of times key occurred in the list, (Count)

密鑰在列表中出現(xiàn)的次數(shù),( Count )

Data structure used:

使用的數(shù)據(jù)結構:

Singly linked list where each node contains a data element say data and the address of the immediate next node say next, with Head holding the address of the first node.

單鏈列表,其中每個節(jié)點包含一個數(shù)據(jù)元素,例如data ,直接下一個節(jié)點的地址說next ,其中Head保留第一個節(jié)點的地址。

Pseudo code:

偽代碼:

Begintemp=HeadCount = 0while(temp != NULL)beginif(temp->data = key)count=count+1endiftemp=temp->linkEnd whileEnd

C程序,用于計算鏈表中元素的出現(xiàn)次數(shù),而無需使用遞歸 (C program to Count the number of occurrences of an element in a linked list without using recursion)

#include <stdio.h> #include <stdlib.h>typedef struct list //linked list node {int data;struct list *next; }node;int main() {node *head=NULL,*temp,*temp1;int choice,count=0,key;//building the linked listdo{temp=(node *)malloc(sizeof(node));if(temp!=NULL){printf("\nEnter the element in the list : ");scanf("%d",&temp->data);temp->next=NULL;if(head==NULL){ head=temp;}else{temp1=head;while(temp1->next!=NULL){temp1=temp1->next;}temp1->next=temp;}}else{printf("\nMemory not avilable...node allocation is not possible");}printf("\nIf you wish to add m ore data on the list enter 1 : ");scanf("%d",&choice);}while(choice==1);//finding occurence of keyprintf("\nEnter the data to find it's occurrence : ");scanf("%d",&key);temp=head;while(temp!=NULL){if(temp->data==key){count=count+1;}temp=temp->next;}printf("\n %d occurred %d times in the list",key,count);return 0; }

Output

輸出量

Enter the element in the list : 1If you wish to add m ore data on the list enter 1 : 1Enter the element in the list : 2If you wish to add m ore data on the list enter 1 : 1Enter the element in the list : 3If you wish to add m ore data on the list enter 1 : 1Enter the element in the list : 4If you wish to add m ore data on the list enter 1 : 1Enter the element in the list : 1If you wish to add m ore data on the list enter 1 : 0Enter the data to find it's occurrence : 11 occurred 2 times in the list

翻譯自: https://www.includehelp.com/c-programs/count-the-number-of-occurrences-of-an-element-in-a-linked-list-without-using-recursion.aspx

數(shù)組重復次數(shù)最多的元素遞歸

總結

以上是生活随笔為你收集整理的数组重复次数最多的元素递归_在不使用递归的情况下计算链接列表中元素的出现次数...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。