clock_t start,end
start=clock()
......
end = clock()
end-start就是了。
单位为ms,但是不能太精亏核确,因为其实返回的是clock数,但是一般够用了,你可以搜一下。
用链表实现的(类似队列的功能,新来的插入到最后, 删除时删掉第一个),纯C的(楼上的貌似两个都不是C的, C中怎么能有引用呢?)...可以看下.../*问题描述:
写一个有关出租车记录的程序 菜单如下 括号内为需要的功能
1 arrive (需要加入一个数字罩祥进入列的末尾)
2 leave (物做搏把当前列第一个数字删除)
3 search(查找一个数字是否存在于目前的列)
4 print (显示已经加入了所有数字)
5 front (显示当前列的第一个数字)
6 back(显示当前列的最后一个数字)
7 length (显示胡碰列中的所有数字)
8 exit (退出)
*/
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include <stdlib.h>
typedef struct _LISTNODE
{
int value
struct _LISTNODE *next
}LISTNODE
void arrive(LISTNODE** head)
{
LISTNODE* temp = (LISTNODE*)malloc(sizeof(LISTNODE))
LISTNODE* curNode = NULL
int value = 0
printf("请输入一个新的数字: ")
scanf("%d", &value)
temp->value = value
temp->next = NULL
if(*head == NULL)
*head = temp
else
{
curNode = *head
while(curNode ->next != NULL)
curNode = curNode->next
curNode ->next = temp
//curNode
}
}
LISTNODE* leave(LISTNODE* head)
{
LISTNODE* temp = NULL
if(head != NULL)
{
temp = head
head = (head)->next
free(temp)
temp = NULL
}
return head
}
void search(LISTNODE* head)
{
int search = 0
LISTNODE* temp = head
int count = 0
if(temp == NULL)
{
printf("链表为空\n")
return
}
printf("请输入一个要查询的数字: ")
scanf("%d", &search)
while(temp != NULL)
{
if(temp->value == search)
{
printf("数字在列表中的位置是第:%d 个\n", count + 1)
return
}
count++
temp = temp->next
}
printf("数字不再列表中\n")
}
void front(LISTNODE* head)
{
if(head == NULL)
{
printf("列表为空\n")
return
}
printf("第一个数字是: %d\n", head->value)
}
void back(LISTNODE *head)
{
if(head == NULL)
{
printf("列表为空\n")
return
}
LISTNODE* temp = head
while(temp->next != NULL)
{
temp = temp->next
}
printf("最后一个数字是: %d\n", temp->value)
}
void print(LISTNODE* head)
{
if(head == NULL)
{
printf("列表为空\n")
return
}
LISTNODE* temp = head
printf("列中的数字是: ")
while(temp != NULL)
{
printf("%d ", temp->value)
temp = temp->next
}
printf("\n")
}
void length(LISTNODE* head)
{
if(head == NULL)
{
printf("列表为空\n")
return
}
LISTNODE* temp = head
int length = 0
while(temp != NULL)
{
length++
temp = temp->next
}
printf("列表的长度是 :%d\n", length)
}
void freeList(LISTNODE* head)
{
LISTNODE* temp = head
if(head == NULL)
{
printf("列表为空\n")
return
}
while(temp->next != NULL)
{
temp = head
head = head->next
free(temp)
}
}
void main()
{
int option = 0
LISTNODE* list = NULL
while(1)
{
printf("/************************出租车记录*****************************/\n")
printf("1 arrive \n2 leave \n3 search \n4 print \n5 front \n6 back \n7 lenght\n8 exit\n")
printf("请输入一个选项(1~8): ")
scanf("%d", &option)
int curLen = 0
switch(option)
{
case 1:
arrive(&list)
break
case 2:
list = leave(list)
// curLen =
break
case 3:
search(list)
break
case 4:
print(list)
break
case 5:
front(list)
break
case 6:
back(list)
break
case 7:
length(list)
break
case 8:
freeList(list)
default:
exit(0)
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)