c语言数据结构
作者:
._006
,
2024-09-10 13:20:55
,
所有人可见
,
阅读 1
//只实现了从头插入和打印链表
#include<stdio.h>
#include<stdlib.h>
typedef struct sqlist
{
int val;
struct sqlist* next;
}sqlist;
//创建新节点
sqlist* creatnode(int val)
{
sqlist* newnode=(sqlist*)malloc(sizeof(sqlist));
newnode->val=val;
newnode->next=NULL;
}
void insertsqlist(sqlist** head,int val)
{
sqlist* newnode=creatnode(val);
newnode->next=*head;
*head=newnode;
}
void printsqlist(sqlist* head)
{
while(head!=NULL)
{
printf("%d",head->val);
head=head->next;
}
printf("\n");
}
// sqlist* initsqlist()
// {
// sqlist* head=(sqlist*) malloc(sizeof(sqlist));
// head->next=NULL;
// return head;
// }
int main()
{
sqlist* head=NULL;
//sqlist* head = initsqlist();
insertsqlist(&head,5);
insertsqlist(&head,6);
printsqlist(head);
return 0;
}