연결된 목록에서 숫자의 발생.
2419 단어 clinkedlistbeginners
예 1:
연결된 목록: 2 6 4 4 5
발생횟수
4 : 2예 2:
연결 리스트 : 3 5 2 7 1 9
발생횟수
8 : 0단계:
item를 선언하여 해당 항목을 찾아야 하는 숫자를 저장합니다. count를 zero(0)로 초기화하여 숫자가 발생한 횟수, 즉 count = 0를 저장합니다. temp 유형의 임시 포인터struct node를 선언합니다. item로 초기화합니다. item와 같은 숫자가 발견될 때까지 연결된 목록 순회를 시작합니다. item와 같은 숫자가 있으면 1만큼 업데이트합니다. count를 인쇄하고 기능을 종료합니다. 주어진 연결 목록에서 number의 발생을 찾는 C 프로그램.
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node * next;
};
void displayLL(struct node * head)
{
int num = 0;
struct node * temp;
temp = head;
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp = temp->next;
num++;
}
}
void occurrence(struct node *head)
{
struct node *temp = head;
int item, count = 0;
printf("\nEnter the number whose occurrence is to find : ");
scanf("%d", &item);
while(temp != NULL)
{
if(temp->data == item)
count++;
temp = temp->next;
}
printf("Occurrence of number %d : %d", item, count);
}
int main()
{
struct node *head = 0, *newnode, *temp, *slow;
int n, choice, newdata;
// Create Linked List //
printf("Enter the number of nodes in the list : ");
scanf("%d", &n);
for(int i = 1; i<=n; i++)
{
newnode = (struct node *)malloc(sizeof(struct node));
printf("Enter the data%d : ", i);
scanf("%d", &newnode->data);
newnode->next = 0;
if(head == 0)
{
head = temp = newnode;
}
else
{
temp->next = newnode;
temp = newnode;
}
}
printf("--------------------------------\n");
printf("Linked list : ");
displayLL(head);
occurrence(head);
}
나는 유사한 블로그를 작성하는 웹사이트www.coderlogs.com를 소유하고 있으므로 더 많은 블로그 게시물을 보려면 웹사이트를 방문하십시오.
Reference
이 문제에 관하여(연결된 목록에서 숫자의 발생.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/dhanashreerugi/occurrence-of-a-number-in-a-linked-list-42e0텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)