本人在刷連結清單題時,由于是新手,是以老是過不去,需要調試,力扣會員開不起,在VS自己建立一個連結清單太麻煩 ,是以就有了今天這個 對于懶人的調節力扣連結清單便捷器
這個東西很簡單,但是很有效
(文章目錄)
1.編寫代碼
打開VS,将如下代碼複制粘貼
#include<stdio.h>
#include<stdlib.h>
struct ListNode
{
int val;
struct ListNode* next;
};
struct ListNode* CreateSList(int* nums,int sz)
{
int i = 0;
struct ListNode* head = NULL;
struct ListNode* tail = NULL;
for (i = 0; i < sz; i++)
{
struct ListNode* newnode = (struct ListNode*)malloc(sizeof(struct ListNode));
if (newnode != NULL)//判斷是否開辟失敗
{
newnode->next = NULL;
newnode->val = nums[i];
}
//尾插
if (tail == NULL)
{
head = tail = newnode;
}
else
{
tail->next = newnode;
tail = newnode;
}
}
return head;
}
int main()
{
int arr[] = { 1,2,3,4,5,6 };
int sz = sizeof(arr) / sizeof(arr[0]);
struct ListNode*plist=CreateSList(arr, sz);
return 0;
}
2.使用
1.找到需要複制的代碼
假設我們在力扣的連結清單題報錯,需要調試
假設力扣上的題如圖報錯,我們隻需将代碼粘貼到剛才編輯好的程式中
2. 輸入數組内容
由于報錯的數組是 1 2 3 4 5 6,是以我們也輸入 1 2 3 4 5 6
3.調試
此時就可以根據數組内容進行調試
3.桌面顯示
1. 複制代碼
複制代碼還是那個架構