c-如何创建一个函数,使整个结构而不仅仅是一个整数入队



编译时,我收到这些消息

[error]变量或字段'Enqueue'声明为无效49 14 C:\weblinky1.cpp[Error]变量或字段"enqueue"声明为无效

49 20 C:\weblinky1.cpp[Error]与"operator*"(操作数类型为"documents"one_answers"node"(不匹配

49 35 C:\weblinky1.cpp[Error]与"operator*"(操作数类型为"documents"one_answers"node"(不匹配

49 45 C:\weblink1.cpp[Error]在"struct"之前应为主表达式

50 14 C:\weblinky1.cpp[Error]变量或字段"dequeue"声明为无效

50 20 C:\weblinky1.cpp[Error]与"operator*"(操作数类型为"documents"one_answers"node"(不匹配

51 14 C:\weblinky1.cpp[Error]变量或字段"getRear"声明为无效

51 20 C:\weblinky1.cpp[Error]与"operator*"(操作数类型为"documents"one_answers"node*"(不匹配

52 15 C:/weblinky1.cpp[Error]变量或字段"getFront"声明为无效

52 21 C:\weblinky1.cpp[Error]与"operator*"(操作数类型为"documents"one_answers"node*"(不匹配

C: \Users\marcheee\Desktop\DSLabTest1_1300054246\weblinky1.cpp在函数"int main(("中:

60 11 C:\weblinky1.cpp[Error]与"operator*"(操作数类型为"documents"one_answers"node*"(不匹配

114 49 C:\weblinky1.cpp[错误]未在此作用域中声明"enqueue">

122 39 C:\weblinky1.cpp[Error]未在此作用域中声明"出列">

126 27 C:\weblinky1.cpp[Error]与"operator=="不匹配(操作数类型为"documents"one_answers"long-long-int"(

138 42 C:\weblinky1.cpp[Error]在此作用域中未声明"deletedocsize">

147 48 C:\weblinky1.cpp[Error]"searchfoldername"未在此作用域中声明

157 32 C:\weblinky1.cpp[Error]在此作用域中未声明"searchID">

165 33 C:\weblinky1.cpp[Error]在此作用域中未声明"averagedocsize">

173 29 C:\weblinky1.cpp[Error]无法将"isEmpty(("从"void"转换为"bool">

182 36 C:\weblinky1.cpp[Error]在此作用域中未声明"getRear">

193 45 C:\weblinky1.cpp[Error]在此作用域中未声明"getFront">

C: \weblink1.cpp在全球范围内:

221 19 C:\weblinky1.cpp[Error]变量或字段'enquee'声明为无效

下面是我的完整代码

enter code here/**
* Queue implementation using linked list in C.
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#define CAPACITY 100    // Queue max capacity

/* Queue structure definition */
struct documents 
{
int id;
char docname[50];
char foldername[50];
float docsize;
struct document * next;
struct document * previous;
};    

//Delacre document variable
struct documents Queue;
//Create node for linked list
struct node
{
struct documents Queue;
struct node* previous;
struct node* next;
};
// Creating an empty linked list
struct node * rear = NULL;
struct node * front = NULL;

/* Queue size */
unsigned int size = 0;

void enqueue(Queue ** rear, Queue ** front, struct documents Queue);
void dequeue(Queue ** front);
void getRear(Queue * rear);
void getFront(Queue * front);
void isEmpty();
void isFull();

int main()
{
int ch, data;
Queue *rear, *front;
struct documents Queue;
int id;
float docsize;
char* docname;
char* foldername;
rear  = NULL;
front = NULL;
/* Run indefinitely until user manually terminates */
while (1)
{
/* Queue menu */
printf("--------------------------------------------n");
printf("  QUEUE LINKED LIST IMPLEMENTATION PROGRAM  n");
printf("--------------------------------------------n");
printf("1. Enqueuen");
printf("2. Dequeuen");
printf("3. Delete by Size of Documentn");
printf("4. Display Documents based on Folder Namen");
printf("5. Enter ID to Display Index where Documents was 
foundn");
printf("6. Display Document Size Averagen");
printf("7. Size of the Queuen");
printf("8. Get Rearn");
printf("9. Get Frontn");
printf("0. Exitn");
printf("--------------------------------------------n");
printf("Select an option: ");
scanf("%d", &ch);

/* Menu control switch */
switch (ch)
{
case 1:
printf("nEnter Document ID#: ");
scanf("%d", &Queue.id);
Queue.id = id;
printf("Enter Document size#: ");
scanf("%f", &Queue.docsize);
Queue.docsize = docsize;
printf("Enter Document name: ");
scanf("%s", &Queue.docname);
strcpy(Queue.docname, docname);
printf("Enter folder name: ");
scanf("%s", foldername);
strcpy(Queue.foldername, foldername);

// Enqueue function returns 1 on success
// otherwise 0
if (enqueue(&rear, &front, Queue))
printf("Document added to queue.");
else
printf("Queue is full.");
break;
case 2:
Queue = dequeue(&front);
// on success dequeue returns element removed
if (Queue == NULL)
printf("Queue is empty.");
else
printf("Queue => %d", Queue.front);
break;
//Delete by Size of Document
case 3:
printf("Enter Document size: ");
scanf("%f", &docsize);
deletedocsize(docsize);
break;
//Display Documents based on Folder Name
case 4:
printf("Enter Document Folder Name: ");
scanf("%s", foldername);
searchfoldername(foldername); 
break;

//Enter ID to Display Index where Documents was found
case 5:
printf("Enter Document ID#: ");
scanf("%f", &id);
searchID(id); 
break;

//Display Document Size Average
case 6:
averagedocsize(); 
break;
case 7: 
// isEmpty() function returns 1 if queue is emtpy 
// otherwise returns 0
if (isEmpty())
printf("Queue is empty.");
else 
printf("Queue size => %d", size);
break;
//get rear of document queue
case 8: 
data = getRear(rear);
if (Queue == Queue.rear)
printf("Queue is empty.");
else 
printf("Rear => %d", Queue.rear);
break;
case 9: 
Queue = getFront(front);
if (Queue == NULL)
printf("Queue is empty.");
else 
printf("Front => %d", Queue.front);
break;
case 0:
printf("Exiting from application.n");
exit(0);
default:
printf("Invalid choice, please input number between (0- 
5).");
break;
}
printf("nn");
}
}

/**
* Enqueues/Insert an element at the rear of a queue.
* Function returns 1 on success otherwise returns 0.
*/
void enqueue(Queue *q)
{
Queue * temp= NULL;
// Check queue out of capacity error
if (isFull())
{
return 0;
}
// Create a new node of queue type
temp = (Queue *) malloc (sizeof(Queue));
// Assign data to new node
temp->docs= en;
// Initially new node does not point anything
temp->next = NULL;
temp->previous = NULL;
// Link new node with existing last node 
if ( (*rear) )
{
(*rear)->next = temp;
}

// Make sure newly created node is at rear
*rear = temp;
// Link first node to front if its NULL
if ( !( *front) )
{
*front = *rear;
}
// Increment quque size
size++;
return 1;
}

/**
* Gets, element at rear of the queue. It returns the element
* at rear of the queue on success otherwise return as 
* error code.
*/
int getRear(Queue * rear)
{
//  if queue is empty otherwise rear.
return (isEmpty())
? NULL
: rear->Queue.rear;
}

/**
* Gets, element at front of the queue. It returns the element
* at front of the queue on success otherwise return  as 
* error code.
*/
int getFront(Queue * front)
{
// if queue is empty otherwise front.
return (isEmpty())
? NULL
: front->Queue.front;
}

/**
* Checks, if queue is empty or not.
*/
int isEmpty()
{
return (size <= 0);
}

/**
* Checks, if queue is within the maximum queue capacity.
*/
int isFull()
{
return (size > CAPACITY);
}
// deleting any node based on position
void Delete(int n)
{
struct documents temp1 =front;
if(n == 1){
front= temp1->next;
free(temp1);
return;
}
int i for(i =0; i<n-2; i++)
temp1 = temp1->next;
struct node* temp2 = temp1->next;
temp1->next = temp2 -> next;
free(temp2);
}
//or using this method
void Dequeue(int n)
{
struct documents temp1;
if(Front == NULL)
{
printf("Queue is empty.n");
}
else
{
int currentIndex = 0;
struct documents *temp1 = (struct documents*)malloc(sizeof(struct 
documents));
bool traversing = true;

tem1 = Front;
temp1 = temp1->Queue;

while(temp1 !=NULL) {
if(temp1.id == n)
{
temp1->previous->next=temp1->next;
free(temp1);
printf("Item Deleted", currentIndex);
return;
}
currentIndex++;
temp1 = temp1->next;
if (temp1 == NULL) {
temp1 = temp1->previous;
}
temp1 = temp1->Queue;
}
}
}
//search by foldername
void searchfoldername(char foldername[])
{
struct documents Queue;
if(Front == NULL)
{
printf("Queue is empty.n");
}
else
{
struct documents *tempp = (struct documents*)malloc(sizeof(struct 
documents));
bool traversing = true;
int currIndex = 0;
tempp = Front;
tempy = tempp->Queue;
Front = Front->next;
while(traversing) {
if(strcmp(tempy->foldername, foldername) == 0))
{
printf(" ID: %dn", tempy->id);
printf("Document Name: %sn", tempy->docname);
printf("Folder Name: %sn", tempy->foldername);
printf("Document Size: %dn", tempy->docsize);
printf("Document positioned at index: %d", currIndex);
return tempy.foldername;
}
currIndex++;
tempp = tempp->next;
if (tempp == NULL) {
tempp = tempp->previous;
}
tempy = tempp->Queue;
}
}
}
//delete document size
Void deletedocsize(int docsize)
{
struct documents Queue;
if(Front == NULL)
{
printf("Queue is empty.n");
}
else
{
struct documents *tempp = (struct documents*)malloc(sizeof(struct 
documents));
bool traversE = true;
int currIndex = 0;
tempp = Front;
tempy = tempp->Queue;
front = front->next;
while(traversE) {
if(strcmp(tempy->docsize, docsize) <= Queue.docsize))
{
free(tempp);
return;
}
currIndex++;
tempp = tempp->next;
if (tempp == NULL) {
tempp = tempp->previous;
}
tempy = tempp->Queue;
}
}
}
};
//Enter ID to Display Index where Documents was found
void searchID(int id)
{
struct documents Queue;
if(Front == NULL)
{
printf("Queue is empty.n");
}
else
{
struct documents *tempp = (struct documents*)malloc(sizeof(struct 
documents));
bool traversing = true;
int currIndex = 0;
tempp = Front;
tempy = tempp->Queue;
Front = Front->next;
while(traversing) {
if(strcmp(tempy->id, id) == Queue.id))
{
printf("Document positioned at index: %d", currIndex);
return tempy.id;
}
currIndex++;
tempp = tempp->next;
if (tempp == NULL) {
tempp = tempp->previous;
}
tempy = tempp->Queue;
}
}
}
//find and display the Average of all document size
void averagedocsize()
{   
struct documents Queue;
if (front == NULL) 
{
printf("n ooops List is Emptyn");
}
else
{
struct documents *tempp = (struct documents*)malloc(sizeof(struct 
documents));
int count = 0;
tempp = front;
Queue = tempp->Queue;
while (tempp != NULL) 
{
if(strcmp(Queue.docsize, docsize) == 0) {
sum=0;
while (count<=rearindex)
{
sum = sum + docsize;
average =rearindex;
}
count++;
}
tempp = tempp->next;
if (tempp == NULL) {
printf("Average Document Size is : %dnn", average);
break;
}
Queue = tempp->;
}
free(tempp);
}
}

您定义了变量Queue而不是类型,并且typedef不完整:

typedef struct Book
{
int bID;
char bName;
char FolderName;
struct Book * next
struct Book * next
} Queue ;
void Enqueue(Queue ** rear, Queue ** front, Queue en) ;

相关内容

最新更新