我将我的文件转换为项目文件,现在它不像以前那样工作了。
我正在使用循环队列 DLL 来插入、删除和显示值。
我的问题是,如果我分别输入 ff 数字:5,4,3我得到3, 2810, 0。这是非常非常错误的。我已经为此工作了几个小时,我在想将它转换为项目文件可能会导致我的一些变量没有被正确声明或其他什么。proj文件也是一个要求。
这是我的代码:
标题:
#ifndef CIRCDLL_H
#define CIRCDLL_H
struct node{
int val;
struct node *next;
struct node *prev;
};
typedef struct node NODE;
int push();
int display();
NODE* create_node(int info);
#endif
主要的:
#include "circdll.h"
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
NODE *new, *ptr, *prev;
NODE *first = NULL, *last = NULL;
int number = 0;
void main()
{
int lim,choice,value,i;
clrscr();
/*get number of nodes*/
printf("Input # of nodes: ");
scanf("%d",&lim);
for(;;)
{
printf("\n\nMENU: \n");
printf("[1]Enqueue\n[2]Dequeue\n[3]Exit\nChoice: ");
scanf("%s",&choice);
clrscr();
switch(choice)
{
case '1':
printf("Input value: \n");
for(i = 1; i <= lim; i++)
{
/*scanf("%d",&value);*/
push();
/* insert_lnode(value); */
}
display();
break;
case '2':
/*delete();
display();*/
break;
case '3':
exit(1);
break;
default:
printf("Incorrect choice!\n\n\n");
break;
}
}
}
创造:
#include "circdll.h"
#include<stdio.h>
NODE* create_node(int info){
int number =0;
NODE *new;
number++;
new = (NODE *)malloc(sizeof(NODE));
new->val = info;
new->next = NULL;
new->prev = NULL;
return new;
}
推:
#include "circdll.h"
#include<stdio.h>
int push(){
int info;
NODE *new, *ptr, *prev,*first, *last;
scanf("%d",&info);
new = create_node(info);
if (first == last && first == NULL){
first = last = new;
first->next = last->next = NULL;
first->prev = last->prev = NULL;
}else{
last->next = new;
new->prev = last;
last = new;
last->next = first;
first->prev = last;
}
return 1;
}
展示:
#include "circdll.h"
#include<stdio.h>
int display(){
int i,number;
NODE *ptr, *prev;
NODE *first, *last;
if (first == last && first == NULL)
printf("\nQueue is empty");
else{
for (ptr = last, i = 0;i < number;i++,ptr = ptr->prev){
printf("\n%d", ptr->val);
}
}
return 1;
}